Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: How do I tighten this with map?

by japhy (Canon)
on Oct 16, 2001 at 19:50 UTC ( #119161=note: print w/replies, xml ) Need Help??

in reply to How do I tighten this with map?

This assumes %fileHash is empty beforehand, and that you meant to escape that . in the regex...
%fileHash = map { /^(\w\w\w\d*):log\.$date$/ ? ($1, $_) : () } readdir DIR;

Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: How do I tighten this with map?
by mikeB (Friar) on Oct 16, 2001 at 20:08 UTC
    Just curious why you replaced \w{3} with \w\w\w.

      That's a little speed optimisation, with /\w{3}/ the regex engine sees the {} construct and has to start counting. If you write it out it's just three single characters in a row, so no counting => quicker.

      Of course, this could be optimised by the regex compiler but that wasn't the case at the time of writing of Mastering Regular Expressions. At least this is where I got this from. As japhy is more up to date on this I assume he has checked that this optimisation hasn't been done in the meantime.

      -- Hofmator

Re: Re: How do I tighten this with map?
by SparkeyG (Curate) on Oct 16, 2001 at 20:06 UTC
    Thank you japhy. That's what I was looking for exactly, and I think I understand most of it.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://119161]
[prospect]: Learning Perl There where 17 videos.
[prospect]: And it was great because I'm using the book as well, to get some more examples or extra information
[ambrus]: Ask merlyn directly. Maybe he has copies.
[ambrus]: write him an email or something
[prospect]: ok I will

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-09-25 10:34 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (279 votes). Check out past polls.