Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re2: Reading the last line of a file in a Pure Way.

by Anonymous Monk
on Aug 04, 2004 at 16:00 UTC ( [id://380034]=note: print w/replies, xml ) Need Help??


in reply to Re2: Reading the last line of a file in a Pure Way.
in thread Reading the last line of a file in a Pure Way.

Please enlighten me

how does this work and what is the }{

I realise -p feeds all lines to the script, sets the ORS to each one but how is this suppressing printing and what is the magic }{

Thanks if you spare the time

  • Comment on Re: Re2: Reading the last line of a file in a Pure Way.

Replies are listed 'Best First'.
Re^2: Re2: Reading the last line of a file in a Pure Way.
by ysth (Canon) on Aug 04, 2004 at 16:26 UTC
    -p wraps a loop around your code. You can see what it looks like:
    $ perl -MO=Deparse -pe '$\=$_}{' LINE: while (defined($_ = <ARGV>)) { $\ = $_; } { (); } continue { die "-p destination: $!\n" unless print $_; }
    In effect, the }{ breaks off the continue part of the while loop that usually prints every line, so it only runs once at the end of file. Since $_ will have been set to undef at end of file, copying it to $\ preserves it so that print will show it. ($\ is implicitly added to each print by perl.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://380034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-16 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found