Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by dasgar (Deacon)
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 wandering the Monastery: (5)
As of 2014-08-31 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls