Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by dasgar (Priest)
on Jan 06, 2014 at 13:56 UTC ( [id://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"} }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-19 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found