Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Useful uses of redo?

by glwtta (Hermit)
on Aug 26, 2004 at 20:29 UTC ( [id://386161]=note: print w/replies, xml ) Need Help??


in reply to Useful uses of redo?

I've used redo once in the last two years or so. Parsing a file with a rather involved format I had several subs to handle specific sections; these sections did not have a closing token of any kind, so the subs had to get a token to find out that they don't recognize it and that their section is over. Rather than futzing it so I can "unget" a token, it seemed easier to just return the current one and redo in the main loop.

so:

while(<FILE>){ if(/Foo/){ $_ = foo(); redo; } elsif { # do lots of other stuff } } sub foo { while(<FILE>){ if(/something or other/){ # so stuff } else { return $_; } } }

Note that foo() doesn't see the line containing "Foo" nor did it need to in this case.

Worked well, certainly don't know if that's doing the Right Thing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found