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

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

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


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

Sure that works, because one can also combine For/When!

Cheers Rolf


Comment on Re^4: Understanding the benefit of Given/When ...
Re^5: Understanding the benefit of Given/When ...
by JavaFan (Canon) on Mar 04, 2010 at 16:56 UTC
    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

        You can put whatever code you want between various when blocks. You can also have more than one default - a default is just a when with a condition that's always true:
        my @test = qw [abc def ghi xyz jkl mno]; for (@test) { say "Testing '$_'"; when (/abc/) {say " Got 'abc'"; continue} say " After when /abc/"; when (/def/) {say " Got 'def'"; next;} say " After when /def/"; when (/ghi/) {say " Got 'ghi'";} say " After when /ghi/"; when (/jkl/) {say " Got 'jkl'"; last;} say " After when /jkl/"; default {say " Default 1"; continue} say " After first default"; default {say " Default 2";} say " After second default" } continue { say " Continue for '$_'"; } __END__ Testing 'abc' Got 'abc' After when /abc/ After when /def/ After when /ghi/ After when /jkl/ Default 1 After first default Default 2 Continue for 'abc' Testing 'def' After when /abc/ Got 'def' Continue for 'def' Testing 'ghi' After when /abc/ After when /def/ Got 'ghi' Continue for 'ghi' Testing 'xyz' After when /abc/ After when /def/ After when /ghi/ After when /jkl/ Default 1 After first default Default 2 Continue for 'xyz' Testing 'jkl' After when /abc/ After when /def/ After when /ghi/ Got 'jkl'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-10-25 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (141 votes), past polls