Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Exiting a loop trickery

by florg (Friar)
on Mar 11, 2004 at 01:48 UTC ( [id://335686]=note: print w/replies, xml ) Need Help??


in reply to Exiting a loop trickery

I think you're looking for last:

#!/usr/bin/perl -w use strict; while (<DATA>) { next unless /trigger/; while (<DATA>) { if ( $_ =~ /timestamp/ ) { print "Found timestamp\n"; last; } } } __DATA__ bar baz trigger qux timestamp quux quuux trigger quuuux timestamp bar
florg

Replies are listed 'Best First'.
Re^2: Exiting a loop trickery
by Roy Johnson (Monsignor) on Mar 11, 2004 at 15:20 UTC
    Or, to avoid nesting loops, use a range operator:
    while (<DATA>) { if (/trigger/ .. /timestamp/) { if ( $_ =~ /timestamp/ ) { print "Found timestamp\n"; last; } } }

    The PerlMonk tr/// Advocate
Re: Re: Exiting a loop trickery
by GaijinPunch (Pilgrim) on Mar 11, 2004 at 06:36 UTC
    Yes... "last", that is it.
    I even dug through my old book... I can't believe I overlooked it. What a rookie error!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found