Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: How do I tighten this with map?

by IraTarball (Monk)
on Oct 16, 2001 at 20:08 UTC ( [id://119168]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I tighten this with map?
in thread How do I tighten this with map?

I'll bet dragonchild thought of this and omitted it for some reason. Not being as wise I'll go ahead and put it out there. This is the same solution without the temporary @files array.
opendir(DIR, $directory) or die $!; my %fileHash = map { (/^(\w{3}\d*):log\.$date$/ => $_); } grep /^\w{3}\d*:log\.$date$/, readdir(DIR); closedir DIR;
I also took the liberty of adding a '\' before the '.' in your regex. It looked like you meant a literal '.' not 'any character'. I think dragonchild's is more easily understood but I like this one.

UPDATE: Even though this works and is all true, look a little lower to japhy's. It's better.

Ira,

"So... What do all these little arrows mean?"
~unknown

Replies are listed 'Best First'.
Re: Re: Re: How do I tighten this with map?
by dragonchild (Archbishop) on Oct 16, 2001 at 21:26 UTC
    The reason I put the temporary @files array is because it might not be temporary. Also, it enhances readability. Just cause you can doesn't mean you should. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Of course you are right. I thought this same thing, and tried to allude to these problems in my post. But I am young and brash and still try to reduce, perhaps too far.

      Mostly because it's fun.

      On an aside, if the @files array is not needed then japhy's solution which removes one whole regex evaluation must be considered better by some definition of efficiency. Those things are expensive.

      Ira,

      "My thoughts are my own, I think."
      ~Me, I think

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://119168]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-19 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found