It doesn't do what you are thinking. Not that I can figure out what you are thinking quite, but I'm quite sure it doesn't do it.
For a start rrv193\d{4}cm => "RNF191", is a syntax error. Possibly you want 'rrv193\d{4}cm' => "RNF191", which at least compiles, but my guess is that you are heading at the problem from the wrong direction. I suspect you are hoping that the hash key in some magical fashion will behave as a regular expression and will "match" any string provided as a "key" that it matches on. Sorry, it don't work that way.
So, what are you really trying to do. Not the solution you've come up with, but the bigger problem you are trying to solve?
My guess is you have a number of these matches and you want to provide a different replacement string for each one. So lets run with that idea for a moment. Consider:
use strict; use warnings; my %Ren2Dol = ( 'rrv193\d{4}cm' => "RNF191", 'rrv194\d{4}cm' => "RNF196", 'rrv195\d{4}cm' => "RNF200", ); while (<DATA>) { chomp; my ($base, $rest) = split /[\.\_]/, $_, 2; my ($match) = grep {$base =~ /$_/} keys %Ren2Dol; if (defined $match) { print "$Ren2Dol{$match}\n"; } else { print "$base\n"; } } __DATA__ rrv1931009cm.new090626 rrv1941009cm.new090626 rrv1951009cm.new090626 rrv1961009cm.new090626 rrv1931234cm.new090626
Prints:
RNF191 RNF196 RNF200 rrv1961009cm RNF191
In reply to Re: regular expression in a hash
by GrandFather
in thread regular expression in a hash
by lamasculo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |