restarting <> (stdio)

J

J

I'm still learning Perl, so i'm sorry if I get the lingo completely wrong.

I have a script that take a filename as an arguement. I process each line of
the file using the while( <> ) statement. That works perfectly.

However, now I need to start at the beginning of the input file. I can't
figure out how to do this to save my life. Any suggestions?

J
 
J

J

After careful consideration, J muttered:


Let me preface with 'I am a perl newbie'.

If you save @ARGV and reset it after <> returns false, the next time <> is
encountered it will re-process @ARGV.

-Mike

thank you so much. That worked perfectly.

J
 
C

Charles DeRykus

I'm still learning Perl, so i'm sorry if I get the lingo completely wrong.

I have a script that take a filename as an arguement. I process each line of
the file using the while( <> ) statement. That works perfectly.

However, now I need to start at the beginning of the input file. I can't
figure out how to do this to save my life. Any suggestions?

If you're talking about re-reading the file with <>,
something like this perhaps:

my $arg = $ARGV[0];
while ( <> ) {
...
}
....
$ARGV[0] = $arg;
while ( <>) {
....

check perlop for details about ARGV and friends...

hth,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top