Thanks! The method you suggested works, though it is not SIMPLE AND
SWEET!!!!!! :-) Thanks, anyways.
Prachi
----Original Message Follows----
From: "J. J. Horner" <[EMAIL PROTECTED]>
To: prachi shroff <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
Subject: Re: substitution problem
Date: Tue, 29 May 2001 15:56:05 -0400
Is there any reason you chose not to do it this way:
# From Perl Cookbook:
open(TRY,"+< try.txt") or die "Couldn't open try.txt: $!\n";
my @lines = <TRY> # Slurp all lines into an
array.
foreach my $line (@lines) { # Iterate through lines here.
$line =~ s/windows/linux/g; # Modify lines here.
}
seek(TRY,0,0) or die "Error seeking file:
$!\n";
print TRY @lines or die "Error writing to file:
$!\n";
truncate(TRY,tell(TRY)) or die "Error truncating file: $!\n";
close(TRY) or die "Error closing
file: $!\n";
It may not be as short and sweet, but it works, and it is easier to debug.
JJ
* prachi shroff ([EMAIL PROTECTED]) [010529 15:41]:
> Hi again!
>
> 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"............
>
>
> Thanks,
> Prachi
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
--
J. J. Horner
"H*","6d6174686c696e40326a6e6574776f726b732e636f6d"
***************************************************
Lure of the Mana Stone (http://www.lotms.com/)
A Rom 2.4 Based MUD.
***************************************************
"H*","6a6a686f726e65724062656c6c736f7574682e6e6574"
Freedom is an all-or-nothing proposition: either we
are completely free, or we are subjects of a
tyrannical system. If we lose one freedom in a
thousand, we become completely subjugated.
<< attach3 >>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com