Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: converting from switch to given-when

by tobyink (Abbot)
on Sep 25, 2012 at 06:07 UTC ( #995491=note: print w/ replies, xml ) Need Help??


in reply to converting from switch to given-when

Try this:

given ($selection) { when ([wxID_YES]) { $self->Wx::LogStatus('You pressed: "Yes"' ) + } when ([wxID_NO]) { $self->Wx::LogStatus('You pressed: "No"' ) + } when ([wxID_CANCEL]) { $self->Wx::LogStatus('You pressed: "Cancel"') + } }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: converting from switch to given-when
by tobyink (Abbot) on Sep 25, 2012 at 06:26 UTC

    PS: if there's any possibility that $selection could potentially contain an arrayref, then my solution might behave a little oddly; you could explicitly protect against arrayrefs:

    sub is_arrayref (_) { ref(shift) eq 'ARRAY' } given ($selection) { when (is_arrayref) { die "unexpected!" } when ([wxID_YES]) { $self->Wx::LogStatus('You pressed: "Yes"' ) + } when ([wxID_NO]) { $self->Wx::LogStatus('You pressed: "No"' ) + } when ([wxID_CANCEL]) { $self->Wx::LogStatus('You pressed: "Cancel"') + } }

    Of course, probably the code that generates $selection can never generate an arrayref, so you don't need to protect against that possibility.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'g

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2016-06-28 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (365 votes). Check out past polls.