Your regexes are inconsistant.
m/(\d+\.\d+\.\d+\.\d+)/ ## four elements with dots s/\w{3} \w{3} \d+ \d+:\d+:\d+ \d{4}/$clocks{$PRTABL}/ ## three with co +lons
In the first you are looking for something that could look like "12.34.56.78".
In the second you are looking for something that looks like "12:23:56".
If the first one matches, (which it appears to be if the print statements works, then the s/// will never match, and so substitution will never occur.
Update: This is unnecessary (Thanks chromatic) You will also need to add /e to the substitution for it to interpolate the hash element.
Finally, there is no reason to do this in two steps, a single substitution would work fine:
my %clocks = ( '12:34:56.78' => 'Grub up!' ); $_ = 'Stuff here: Mon Feb 12 12:34:56.78 2005 More stuff here'; s/\w{3} \w{3} \d+ (\d+:\d+:\d+\.\d+) \d{4}/$clocks{$1}/; print; ## Will print "Stuff here: Grub up! More stuff here"
You'll have to make sure that your regex and hash keys match whatever form the (time?) field in your data looks like.
A final thought. If the field your keying your hash on is a time--with 10ths and hundreths of seconds?--then your hash will need to be enormous:
60*60*24*100 = 8.64 million keys, which will take approximately 1.2 GB of ram!
In reply to Re: replace with hash value?!
by BrowserUk
in thread replace with hash value?!
by lcollins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |