Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi.

A similar discussion was had a few months ago here: Set Operators. Everyone seemed to come up with different answers, but like so much other stuff with Perl, "it depends" was the best answer.

If you can afford the memory, and your list of values to test against is reasonably small, building a hash slice is a nice "Perlish" solution. It can also pay long-term if you are going to be doing these searches over and over again.

On the other hand, if you only have a few values to test against, hashes may be more trouble than they're worth - just use a foreach loop. An example of where this would be perfectly appropriate would be parsing commandline arguments manually (although you should generally use some sort of Getopt).

However, since it is implemented directly in C as a core function, you would have to work hard to beat grep in terms of raw speed. At the same time, you are also guaranteed that grep will examine every item of the search list, every time. You get no chance to `last' out of the loop early if your needs have already been matched. Raw speed only scales so far...

Unfortunately, the old adage still stands - know your data. Only you can decide which approach works best; and if in doubt - "use Benchmark;". :-)

Cheers,

-- Dave :-)


$q=[split+qr,,,q,~swmi,.$,],+s.$.Em~w^,,.,s,.,$&&$$q[pos],eg,print

In reply to Re: Dynamic regexp from array values by DaveH
in thread Dynamic regexp from array values by Heidegger

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2023-06-03 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (17 votes). Check out past polls.

    Notices?