Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Just another Perl shrine
 
PerlMonks  

Re: How do I read the files in @ARGV one by one

by bjelli (Pilgrim)
on Mar 19, 2001 at 21:39 UTC ( #65478=note: print w/ replies, xml ) Need Help??


in reply to How do I read the files in @ARGV one by one

The trouble with your code is that <> does advanced magic: it reads in all the files on the command line line by line. You can find out which file you are reading right now by looking at $ARGV.

So for your little problem, you could remember what $ARGV was when you last read a line and check if $ARGV has changed:

my $OLDARGV; while (<>) { push(@data, $ARGV) if $ARGV ne $OLDARGV; push(@data, $_); $OLDARGV=$ARGV; }

But I admit that Masems code is probably easier to figure out.

--
Brigitte    'I never met a chocolate I didnt like'    Jellinek
http://www.horus.com/~bjelli/         http://perlwelt.horus.at


Comment on Re: How do I read the files in @ARGV one by one
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-04-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls