Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: “A meeting at the Liquor-Vodka Factory”, or… same ARRAY questions again?!!

by polettix (Vicar)
on Sep 03, 2005 at 15:18 UTC ( [id://488926]=note: print w/replies, xml ) Need Help??


in reply to “A meeting at the Liquor-Vodka Factory”, or… same ARRAY questions again?!!

As you already pointed out, you're not describing a problem, but rather a family of related problems. Each of which has a solution that best fits.
Traversing an array should never be used for searching
This really hits me, in particular the never. If your search needs are rare, for example, or you don't have particular needs in term of efficiency - why not? Keeping it simple seems the most winning solution to me, human cycles are quite more expensive than CPU ones. And List::Util contains tools that are there only to be put directly into production code (yes, it's part of the CORE MODULES).

More or less, I'd use a hash when I know in advance that I'll do a lot of lookups. Building the hash from the array has its cost, both in term of space and time (yes, you have to traverse the whole array!), so I'd keep this solution for occasions where I really need it.

Last, but not least, your request for code is funny. Why not posting an initial implementation? The description seems already near to Perl code, and it would have probably helped you better than a look for cut-and-paste.

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.
  • Comment on Re: “A meeting at the Liquor-Vodka Factory”, or… same ARRAY questions again?!!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found