Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Given When Syntax

by LanX (Archbishop)
on Mar 15, 2014 at 15:54 UTC ( #1078454=note: print w/replies, xml ) Need Help??


in reply to Given When Syntax

I'm mobile and can't spot or test your problem.

Normally I recommend replacing given/when with for/if-constructs.

But in this particular case I don't understand why you are not simply using an array or a hash, holding the number's names.

Cheers Rolf

( addicted to the Perl Programming Language)

edit

Ehm... did you activate switch?

 use feature "switch"; or use 5.010;

update

DB<103> @num=qw/Zero One Two Three Four/ => ("Zero", "One", "Two", "Three", "Four") DB<104> $var=2; print "$var is $num[$var]"; => 1 2 is Two

Replies are listed 'Best First'.
Re^2: Given When Syntax
by Deep_Plaid (Acolyte) on Mar 15, 2014 at 16:20 UTC

    Hi Rolf. As I mentioned to HazyLife, I could have used Switch and I also thought of using an array, as you have demonstrated above, but in the actual program I'm running I'm already in the middle of hash. I will try if I can do this there, however. I'm trying to do this the most efficient way and I don't have a whole lot of PERL experience. Thanks for replying!!

      I think you are getting it wrong, Given/When are activated by the feature pragma with the keyword switch or with an indication of the first Perl version which supports it.(not a Switch module)

      The deprecation also affects Given/When, because of the built-in use of smartmatch. We had a discussion recently, should be easily found.

      In the post above I updated a link to a thread showing how to easily emulate Given/When with For/If!

      HTH! :)

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2019-09-23 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (279 votes). Check out past polls.

    Notices?