On Fri, 2009-03-20 at 18:48 +0100, Gunnar Hjalmarsson wrote:
> Martin Spinassi wrote:
> > Is there any way to open a file for input and output at the same time?
> 
> Yes. Open it with the '+<' MODE.
> 
>      open my $fh, '+<', $file or die "Couldn't open $file: $!";
>      my @keep;
>      while ( <$fh> ) {
>          next if /^--/;
>          push @keep, $_;
>      }
>      seek $fh, 0, 0;
>      truncate $fh, 0;
>      print $fh @keep;
> 
> http://perldoc.perl.org/functions/open.html
> 
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
> 


Thanks!!

That's what I was searching for. Anyway, looks like I've to search some
info about "seek" and "truncate", I've seen them in some scripts, and
seems that is very used..

Thanks again Gunnar.


Martín


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to