http://www.perlmonks.org?node_id=833139


in reply to Re: Hash of Regex
in thread Hash of Regex

$VAR1 = { 'int' => 'float', 'brown' => 'yellow' };

(note to the OP)  In case you wonder why this is:

my %dict = ( 'brown' => 'yellow', /int(\d+)/ => 'int', /float(\d+)/ => 'float', );

is the same as

my %dict = ( 'brown' => 'yellow', $_ =~ /int(\d+)/ => 'int', $_ =~ /float(\d+)/ => 'float', );

which (in this case) is the same as

my %dict = ( 'brown' => 'yellow', () => 'int', () => 'float', );

which is the same as

my %dict = ( 'brown' => 'yellow', 'int' => 'float', );

Replies are listed 'Best First'.
Re^3: Hash of Regex
by Anonymous Monk on Apr 06, 2010 at 22:49 UTC
    Why / how did this
    my %dict = ( 'brown' => 'yellow', () => 'int', () => 'float', );
    become this??
    my %dict = ( 'brown' => 'yellow', 'int' => 'float', );
      For Perl => is just a comma, and empty lists () are ignored when flattening lists.

      perl -e' @a=(1,2,(),(),3);print "@a"' 1 2 3

      Cheers Rolf

      Empty elements (lists) in a list collapse,  e.g. (1, (), 2, 3, (), (), 4) is the same as (1, 2, 3, 4).