Randal L. Schwartz wrote:
"Gunnar" == Gunnar Hjalmarsson <nore...@gunnar.cc> writes:
Gunnar> Martin Spinassi wrote:
Is there any way to open a file for input and output at the same time?
Gunnar> Yes. Open it with the '+<' MODE.
Gunnar> open my $fh, '+<', $file or die "Couldn't open $file: $!";
Gunnar> my @keep;
Gunnar> while ( <$fh> ) {
Gunnar> next if /^--/;
Gunnar> push @keep, $_;
Gunnar> }
Gunnar> seek $fh, 0, 0;
Gunnar> truncate $fh, 0;
And then your power fails at this moment, and you've lost the entire file.
Much safer to use in-place editing. See $^I in perlvar.
The OP also said:
"... I want to edit those files, but couldn't make the edition infile,
and do not want to duplicate files for just editing them (using $^I)"
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/