Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Not getting desire output by using switch statement in Perl

by choroba (Chancellor)
on Jan 06, 2014 at 11:40 UTC ( #1069487=note: print w/ replies, xml ) Need Help??


in reply to Not getting desire output by using switch statement in Perl

Your condition is not doing what you think:
perl -MO=Deparse,-p -e '$a eq "a" || "b" || "c" || "d"' (((($a eq 'a') or 'b') or 'c') or '???');
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Comment on Re: Not getting desire output by using switch statement in Perl
Download Code
Replies are listed 'Best First'.
Re^2: Not getting desire output by using switch statement in Perl
by rammohan (Acolyte) on Jan 06, 2014 at 11:53 UTC
    Then how I'm achieve that result?(me question is if I give a string then it returns output result with numeric values like based on alphabetic value in numeric type- a is 1, b is 2,c is 3 in this similar way up to..... z is 26 )
      Easy. See ord:
      if ($a =~ /[a-z]/) { print ord($a) - 96; } else { print "Everything else"; }
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2016-05-02 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?