Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: anonymous filehandes?

by grinder (Bishop)
on Jul 09, 2007 at 17:21 UTC ( [id://625661]=note: print w/replies, xml ) Need Help??


in reply to Re^2: anonymous filehandes?
in thread anonymous filehandes?

Is the Perl interpreter smart enough to close files in the same manner as the first example

I'm 99.9999% sure that that is the case, without looking at the source. You can use the magic $ARGV variable to see where you are:

my $prev; while (<>) { if (not defined $prev or $prev ne $ARGV) { print "now reading from $ARGV\n"; } print; $prev = $ARGV; }

When run as "reader f1.txt f2.txt f3.txt" you'll be able to see when the program begins to read from the next file in the list. If you pipe into STDIN, it'll say "reading from -". I believe the most unambiguous terminology is to say that you are reading from the diamond operator.

This is not obscure... it's useful.

update: Oh, and, if you need to know when you reach the end of a file (not just when the new one begins), you can do that too, with eof.

while (<>) { if (not defined $prev or $prev ne $ARGV) { print "reading $ARGV\n"; } print; print "and that's the end of $ARGV\n" if (eof); $prev = $ARGV; }

When I get to that level of convoluted logic, however (especially if lots of other stuff is going on), my head usually explodes.

• another intruder with the mooring in the heart of the Perl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found