Hello,
I am sorry, I don't know what are you doing wrong, but this
code works for me.
use strict;
#use warnings;
use Tie::File;
my $file
= 'file.txt';
my $version1 = "JITENDRA";
tie my(@array), 'Tie::File',
$file or die "Cannot open file `$file': $!";
for(@array) {
#warn "F: ",
$_;
s/%VERSION%/$version1/g;
#warn "S: ", $_;
}
untie @array;
But
why to use such big hammer like Tie::File for the easy operation.
Try
just from command line
perl -i.orig -p subst.pl file.txt
where
subst.pl contains one line
s/%VERSION%/ABC/
See perldoc perlrun, the
examples under the -i option.
It is possible tu run this whole from
command line
perl -i.orig -pe ^"s/^%VERSION^%/XYZ/g^" file.txt
but
under windows you need to escape percent signs complicatedly.
http://superuser.com/questions/409546/escaping-s-in-file-folder-names-at-the-command-line
Regards,
Hans
Dne 04.12.2014 11:36, Jitendra Barik napsal:
> HI
All,
>
> My code is:
>
> $version1 = "JITENDRA";
>
> tie
@array,Tie::File,"$rtf1" or die($!);
>
> for(@array){
> #print "Hi";
>
> s/%VERSIONS%/$version1/g;
>
> }
> untie(@array);
>
> FILE:
>
***********************************************************************
>
> VERSION %VERSION%, Hello,HI
>
> INSTALLATION NOTES
>
> The
driver can be installed either during OS setup or as an update --
>
>
REVISION HISTORY
>
> %VERSION%
>
>
**************************************************************
>
> In
the above file, the first %VERSION% is not substitute but second one is
repalced bt string JITENDRA. I am executing in windows OS. Could you
please help me why it is not working.
>
> Regards,
> Jitendra