Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: How to check if a variable's value is equal to a member of a list of values

by LanX (Saint)
on Mar 25, 2013 at 14:28 UTC ( [id://1025316]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to check if a variable's value is equal to a member of a list of values
in thread How to check if a variable's value is equal to a member of a list of values

It should

  • smartmatch is implemented in C
  • grep doesn't stop after matching.

    Unfortunately all the use cases of smartmatch are hard to remember.

    For repeated lookups a prepared hash scales certainly better.

    You're free to check this with benchmarks or search for older discussions.¹

    I hoped smartmatch could at least handle the stringification limitation of hashes, but nope:

    DB<141> $h1={} => {} DB<142> $h1 ~~ [$h1] => "" DB<143> 5 ~~ [5] => 1

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    Update

    ¹) Brian got deep into benchmarking :) http://stackoverflow.com/questions/3951812/how-fast-is-perls-smart-match-operator-for-searching-scalar-in-an-array

    • Comment on Re^3: How to check if a variable's value is equal to a member of a list of values
    • Download Code
  • Replies are listed 'Best First'.
    Re^4: How to check if a variable's value is equal to a member of a list of values
    by McA (Priest) on Mar 25, 2013 at 14:42 UTC

      Thank you. An intersting link. I have to admit that I haven't worked with the smart match operator. It's a little bit too much "Eierlegendenwollmilchsau" (1) for me. And what I read about it confirmed to wait with it. But probably I'm too old fashioned.

      McA

      (1) Best translation I could find on dict.leo.org: jack of all trades device

    Log In?
    Username:
    Password:

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

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

      No recent polls found