in reply to Re: Switch statement?
in thread Switch statement?
Sorry for giving you code that didn't directly work earlier - please reply directly to my posts if you expect me to read them, as only then I get a notification.
The correct code for creating the list of keys and the list of where they should be mapped to is the following. Previously, I had thought that the range operator .. would also work for characters outside the printable range, but it works its magic only for strings between A and Z...
First, always keep use strict; enabled - it will help you catch spelling errors and other hard to track errors. use strict; is your friend!
The initialization of the validchars map can be done as follows:
if ( $act eq '-a' ) { %validchars = map { $_ => uc $_ } map { pack "C", $_ } ( 0 .. 255 ); } elsif ( $act eq '-c' ) { %validchars = map { $_ => $_ } map { pack "C", $_ } ( ord('A').. ord('Z'), ord('a').. +ord('z') ); };
The sequence of map calls is converting the list at the end of that sequence in two steps. First, the list is converted from the numbers to the characters represented by these numbers, and then, in the first map, every character is converted to a pair mapping the character onto the character that is to be counted.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Switch statement?
by crep (Novice) on Jul 21, 2004 at 13:53 UTC |