Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Understanding the benefit of Given/When ...

by JavaFan (Canon)
on Mar 04, 2010 at 16:36 UTC ( #826737=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Understanding the benefit of Given/When ...
in thread Understanding the benefit of Given/When ...

my @test = qw[abc def ghi xyz]; my @res; for (@test) { when (/abc/) {push @res, "abc"; continue} when (/def/) {push @res, "def"; last} when (/xyz/) {push @res, "xyz"; next} default {push @res, "default"} } continue { print "FOR/CONT($_): @res\n"; @res = (); } __END__ FOR/CONT(abc): abc default


Comment on Re^3: Understanding the benefit of Given/When ...
Download Code
Replies are listed 'Best First'.
Re^4: Understanding the benefit of Given/When ...
by LanX (Canon) on Mar 04, 2010 at 16:42 UTC
    Sure that works, because one can also combine For/When!

    Cheers Rolf

      Which means you can have your continue block - just spell given as for - you'd save 2 keystrokes as well.
        which should also mean that one can mix when andif/unless within a for-block -one would save keystroke for continue and next statements! 8)

        Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2015-07-30 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls