Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to 'peek' at next line while parsing with <>

by japhy (Canon)
on Jul 11, 2002 at 16:57 UTC ( #181072=note: print w/replies, xml ) Need Help??


in reply to How to 'peek' at next line while parsing with <>

Well, you can always use redo()...
while ($line = <>) { # redo comes HERE # do something my $next = <>; if ($next !~ /^#/) { # if the next line DOES NOT start with a "#" # reuse it and restart this iteration of the loop $line = $next; redo; } }
Or you can use seek() and tell() to make Perl think nothing ever happened:
while ($line = <>) { # ... my $pos = tell ARGV; my $next = <>; seek ARGV, $pos, 0; # ... }

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-03-28 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (167 votes). Check out past polls.

    Notices?