lightoverhead has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
To my understanding "+<" will not clobber the contents of file when you try to write sth to it.
but...
#!/usr/bin/perl -w use strict; open (F, "+<",$ARGV[0]); my $out = ""; while(<F>){ chomp; $out .= $_."\tadd sth\n" if($.%2 == 0); } seek(F,0,0); print F $out; close(F);
I was expecting to insert the $out contents at the beginning of the file.
But it just removes the old contents of the file and prints the $out contents instead.
Does anyone have insight on this? Thank you!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: questions regarding "+<"
by choroba (Cardinal) on May 15, 2014 at 19:42 UTC | |
by lightoverhead (Pilgrim) on May 15, 2014 at 19:56 UTC | |
by davido (Cardinal) on May 15, 2014 at 20:02 UTC | |
by lightoverhead (Pilgrim) on May 15, 2014 at 20:14 UTC | |
by davido (Cardinal) on May 15, 2014 at 20:38 UTC | |
by choroba (Cardinal) on May 15, 2014 at 20:11 UTC |
Back to
Seekers of Perl Wisdom