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

Re^4: The most efficient way for searching for an element in an array?

by afoken (Chancellor)
on Jan 08, 2016 at 19:54 UTC ( [id://1152334]=note: print w/replies, xml ) Need Help??


in reply to Re^3: The most efficient way for searching for an element in an array?
in thread The most efficient way for searching for an element in an array?

my @arr = qw(Apple Banana Tiger Lion Cat Turtle); my $arr = join("|", @arr); my $flag1 = ($arr =~ m/Apple|Turtle/) ? 1 : 0;

That breaks as soon as the elements of @arr may contain the string used to join the arrays. Also, it roughly doubles the memory usage. Imagine a 2 GByte @arr on a machine with 4 GByte RAM.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found