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.

In reply to Re: replace with hash value?! by BrowserUk
in thread replace with hash value?! by lcollins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.