Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Something eq hashref key

by haukex (Archbishop)
on Mar 25, 2019 at 13:44 UTC ( #1231656=note: print w/replies, xml ) Need Help??


in reply to Something eq hashref key

I'm not sure I fully understand your question, maybe you could provide a few more examples of what should be true and what should be false, but are you perhaps looking for exists? As in: if ( exists $fields->{field1} )

Replies are listed 'Best First'.
Re^2: Something eq hashref key
by LanX (Sage) on Mar 25, 2019 at 14:06 UTC
    On a side note, it's a pity we can't use exists on hash slices ...

    DB<9> exists @h{"a","z"} exists argument is not a HASH or ARRAY element or a subroutine at (eva +l 18)...

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      In a recent thread it was shown that hash slices are not faster than maps, exists on hash slices is not needed.

      sub slex { my $h = shift; return map { exists $h->{$_} || 0 } @_ } my %h = map { $_ => 1 } 'a'..'t'; my @bool = slex \%h, 'a'..'z'; print "@bool\n";
        You must be joking! (?)

        The benchmark was about non intuitive performance of constant lists.

        Slices are 5 times faster than maps in this example, and the overhead of join is still included

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re^2: Something eq hashref key
by Anonymous Monk on Mar 25, 2019 at 13:51 UTC
    Thank you so much, haukex.

    Yes, "exists" is what I was looking for.

    Thank you for the enlightenment :))

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-10-07 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (30 votes). Check out past polls.

    Notices?