in reply to Hash of Regex
Try to check content of the hash:
And if you'd use warnings...use strict; my $test = 'The brown fox int(10) over float(200) fence.'; my %dict = ( 'brown' => 'yellow', /int(\d+)/ => 'int', /float(\d+)/ => 'float', ); use Data::Dumper; warn Dumper \%dict; __END__ $VAR1 = { 'int' => 'float', 'brown' => 'yellow' };
Perhaps you also will be interested in:
my %dict = ( 'brown' => 'yellow', qr/int(\d+)/ => 'int', qr/float(\d+)/ => 'float', );
Update: And what you actually want, if I got you right, is:
use strict; my $test = 'The brown fox int(10) over float(200) fence.'; my %dict = ( 'brown' => 'yellow', 'int\(\d+\)' => 'int', 'float\(\d+\)' => 'float', ); for my $i ( keys %dict ) { $test =~ s/$i/$dict{$i}/gi; } print "$test\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash of Regex
by almut (Canon) on Apr 06, 2010 at 22:19 UTC | |
by Anonymous Monk on Apr 06, 2010 at 22:49 UTC | |
by LanX (Saint) on Apr 06, 2010 at 22:56 UTC | |
by almut (Canon) on Apr 06, 2010 at 22:56 UTC | |
|
Re^2: Hash of Regex
by Anonymous Monk on Apr 06, 2010 at 22:46 UTC | |
by crashtest (Curate) on Apr 06, 2010 at 23:23 UTC | |
|
Re^2: Hash of Regex
by 7stud (Deacon) on Apr 06, 2010 at 22:22 UTC | |
by zwon (Abbot) on Apr 06, 2010 at 22:33 UTC | |
by bichonfrise74 (Vicar) on Apr 06, 2010 at 22:41 UTC |