$hash{@array} is wrong, you want @hash{@array}.

But since you're (rightly) using exists, you can reduce that even further:

@hash{@array} = (); Some quick testing shows this is about 25% faster:
#!/usr/bin/perl -w use strict; use Benchmark; sub is_elem_of_A { my ($x, %hash) = shift; @hash{@_} = (1) x @_; exists $hash{$x} } sub is_elem_of_B { my ($x, %hash) = shift; @hash{@_} = (); exists $hash{$x} } my %param = ( short => [ qw(one one two three four five) ], long => [ 10, 1 .. 10000 ], ); for(qw(short long)) { print "Timing with $_ list\n"; my $list = $param{$_}; timethese -5, { xop => sub{ is_elem_of_A @$list }, emptylist => sub{ is_elem_of_B @$list }, }; } __END__ Timing with short list Benchmark: running emptylist, xop, each for at least 5 CPU seconds... emptylist: 6 wallclock secs ( 5.29 usr + 0.04 sys = 5.33 CPU) @ 42 +362.48/s (n=225792) xop: 6 wallclock secs ( 5.35 usr + 0.04 sys = 5.39 CPU) @ 31 +733.58/s (n=171044) Timing with long list Benchmark: running emptylist, xop, each for at least 5 CPU seconds... emptylist: 5 wallclock secs ( 5.28 usr + 0.01 sys = 5.29 CPU) @ 22 +.12/s (n=117) xop: 6 wallclock secs ( 5.50 usr + 0.02 sys = 5.52 CPU) @ 15 +.40/s (n=85)

Makeshifts last the longest.


In reply to Re^4: Set Operators by Aristotle
in thread Set Operators by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.