Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Exiting a loop trickery

by florg (Friar)
on Mar 11, 2004 at 01:48 UTC ( #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
Node Status?
node history
Node Type: note [id://335686]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-05-22 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?