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

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

by dasgar (Curate)
on Jan 06, 2014 at 13:56 UTC ( #1069515=note: print w/ replies, xml ) Need Help??


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

Although others have suggested using ord, I would have used a different approach by using Number::Latin.

The code below looks at a character and if its an alphabet (a-z), it will convert it to an integer (regardless of case) and print it. And it will print the string "Something else" if the character is not an alphabet character.

use strict; use warnings; use feature 'say'; use Number::Latin; my $string1 = 'abcdef ghijkl-mnopq,rstuv.wxyz'; my $string2 = uc($string1); say $string1; for my $char (split //,$string1) { if ($char =~ /[a-zA-Z]/) {say latin2int($char);} else {say "Something else"} } say $string2; for my $char (split //,$string2) { if ($char =~ /[a-zA-Z]/) {say latin2int($char);} else {say "Something else"} }


Comment on Re: Not getting desire output by using switch statement in Perl
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2015-07-07 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls