Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Working out which file a script is working on

by danger (Priest)
on Jul 10, 2001 at 09:50 UTC ( [id://95244]=note: print w/replies, xml ) Need Help??


in reply to Working out which file a script is working on

As japhy mentions, the $ARGV holds the current filename when reading from either <> or <ARGV>. However, note that the line number in $. (and the one reported from the die function) won't be reset between files unless you explicitly check for the end of files and close the filehandle (using the eof function without parens --- see perlfunc:eof). The basic framework is:

#!/usr/bin/perl -w use strict; while(<>){ chomp; my $verified = 0; # do verification stuff die "problem in file $ARGV at line $." unless $verified; } continue { close ARGV if eof; }

Note, you can put the eof test at the bottom of the loop rather than in the continue block, but if it is in the continue block it'll still be checked even if you use next inside your loop.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found