> I am having problems using the "s///" operator for substitution in of
a
> particular pattern in a specified file.
> For eg.
>
> open(TRY,"+<try.txt");
> while(<TRY>)
> {
> $_ =~ s/a/p/g;
> }
>
> Is this the right way of doing it? And with what access mode shall I
open
> the file ( >> or +> or +< ) ? And is the while loop
> fine? What happens with this code is this code itself gets written in
> "try.txt"............
Weird.
You have no print statement, so I would not
have expected any changes to be committed
back to disk, let alone somehow getting your
code!
Anyhow, the more usual perl idiom would be:
perl -pi.bak e 's/a/p/g' try.txt
or maybe:
#!/usr/bin/perl -i
while (<>)
{
s/a/p/g;
}
or other variation.