Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: ending this loop

by arturo (Vicar)
on Aug 10, 2001 at 20:56 UTC ( [id://103950]=note: print w/replies, xml ) Need Help??


in reply to ending this loop

I'm not sure what you're asking here. Is the idea that if you find the string you're looking for, print the message and end? If that's the case, then what you want is last :

my $found=0; while(<>) { if (/woot!/) { print "You said woot!\n"; $found=1; last; } } print "Nobody said 'woot!'\n" unless $found;

Notice also the addition of the variable that's set to a true value if you find the string you're looking for.

HTH (Oh, and BTW, since this is a public site ... you might want to pick less 'ripe' examples =)

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-26 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found