Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

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

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

So, why even want a continue block on given/when? It's not needed, and isn't consistent.

I see what you mean, maybe I'm still too attached to the concepts of the workaround...(which is easier to understand for me)

Anyway I think you have a plus because you can use last for leaving without executing the continue block.

# using continue-block my @res; for (@test){ push (@res, "abc") if (/abc/); push (@res, "def") && last if (/def/); push (@res, "xyz") && next if (/xyz/); push (@res, "default"); } continue { print "\nFOR/CONT($_):",@res; @res=(); }


=== For/Continue FOR/CONT(abc): abc default

Cheers Rolf

Replies are listed 'Best First'.
Re^3: Understanding the benefit of Given/When ...
by JavaFan (Canon) on Mar 04, 2010 at 16:36 UTC
    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
      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://826731]
[thezip]: So, we have a small deployment coming up soon for a project. What is the general name for the project management documentation that details the tasks and schedules/ sequences for the execution of the deployment?
[thezip]: Deployment checklist?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-02-23 17:47 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (350 votes). Check out past polls.