Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^4: perl -i -pe ... with eof() testing

by Anonyrnous Monk (Hermit)
on Feb 08, 2011 at 20:38 UTC ( #887046=note: print w/replies, xml ) Need Help??

in reply to Re^3: perl -i -pe ... with eof() testing
in thread perl -i -pe ... with eof() testing

Thanks, you're right.

Just for the record: I had confused myself unnecessarily by not putting a separator in between the cat of file1 and file2. Which made me wonder why the magical file handle is only being advanced by eof() at the very end, and not at every file boundary.  When you do it properly, however, i.e. something like

cat file1 echo --- cat file2

the output is

... --- perl output to stdout --- line3 opt=bar --- cat after --- line1 line2 --- line3 line1 line2

which shows that line3 of the first file does in fact belong to file2 after the processing...

P.S. I've now settled on suggesting my collegue

perl -i -pe '$f||=s/opt=.*/opt=bar/; $_.="opt=bar\n" if !$f && !@ARGV +&& eof' files...

(but unfortunately it took a little too long to get working to leave an "it's easy with Perl" impression — that's my fault, however :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://887046]
[Corion]: Yeah, you need bool to get a true value, and the rest to return the other value ;)
[choroba]: perl -wE '{package o; use Tie::Scalar; use parent -norequire => "Tie::StdScalar" ;sub FETCH { "x" x int rand 2}} tie my $x, "o" ; say $x for 1 .. 10'
[choroba]: for complete ness

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2017-07-27 13:54 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (414 votes). Check out past polls.