Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by LanX (Saint)
on Mar 04, 2010 at 16:42 UTC ( [id://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 ...

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://826738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2024-04-18 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found