in reply to replace with hash value?!

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!


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

Replies are listed 'Best First'.
Re^2: replace with hash value?!
by lcollins (Novice) on Jan 19, 2005 at 13:48 UTC
    The reg are not looking for the same thing. the first is looking for an IP address. the ip is the key for the hash, so I save it in $PRTABL=$1. then use it to replace the "time" in the next reg with the value in $clocks{$PRTABL}. except $clocks{$PRTABL} never has a value in s///, however I can print the value on the next line?

      The I would have to guess that your second regex is not matching.

      However, if you want to receive some help--rather than my half arsed guessing--you should try giving us some real information.

      Ie. Some real, runnable code--pasted from your own test program--that demonstrates the failure, including the sample data that causes it to fail.


      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.