Ace128 has asked for the wisdom of the Perl Monks concerning the following question:
And Im using it like so:my %inst = ( "unimp" => "\e[31munimp\e[0m", "be" => "\e[31mbe\e[0m", "bne" => "\e[31mbne\e[0m", "ba" => "\e[31mba\e[0m", "bl" => "\e[31mbl\e[0m", "call" => "\e[31mcall\e[0m", "jmp" => "\e[31mjmp\e[0m", );
Now, this all works fine as long as the found variable, $2, exists as a key in the hash. I was wondering if anyone here have some neat way of making it possible to add some kind of "default" key in the hash (without having some kind of function ofcource, that checks). Something like:s/(^.*<)\:([a-z]+)>/$1$inst{$2}/;
So, the "default" is used if nothing else matches... Yes, a function can be used, but I thought there must be some cool perlish way doing this! ;)"default" => "\e[31m$the_key\e[0m",
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Having a "default" hash value!
by blokhead (Monsignor) on Feb 26, 2006 at 00:04 UTC | |
|
Re: Having a "default" hash value!
by borisz (Canon) on Feb 26, 2006 at 00:13 UTC | |
|
Re: Having a "default" hash value!
by graff (Chancellor) on Feb 26, 2006 at 14:34 UTC | |
by Ace128 (Hermit) on Mar 03, 2006 at 07:40 UTC | |
by graff (Chancellor) on Mar 03, 2006 at 08:05 UTC | |
by Ace128 (Hermit) on Mar 04, 2006 at 17:58 UTC | |
|
Re: Having a "default" hash value!
by QM (Parson) on Feb 26, 2006 at 16:39 UTC | |
|
Re: Having a "default" hash value!
by Ace128 (Hermit) on Feb 26, 2006 at 01:21 UTC |