On 8/15/07, Amir E. Aharoni <[EMAIL PROTECTED]> wrote:
> grep may be clever, but it iterates over the whole list, and i don't need it.
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

On 8/15/07, Peter Gordon <[EMAIL PROTECTED]> wrote:
> @w = (1, 2, 3, 4, 5) ;
> grep { $w->{$_} ++ } @w ;
> print "found\n" if exists $w->{3} ;

On 8/15/07, Eli Billauer <[EMAIL PROTECTED]> wrote:
> @w = (1, 2, 3, 4, 5) ;
> print "Found\n" if (grep { $_ == 3 } @w);

He said he does not want to iterate over the entire list- read the
question! The list could be big, and the item you want could be the
1st.

Any hash-based solution suffers from the exact same problem.


On 8/15/07, Shlomi Fish <[EMAIL PROTECTED]> wrote:
> use List::MoreUtils qw(any);
> my @set = (1, 2, 3, 4, 5);
> if (any { $_ == 3 } @set) {  print "found\n" }

Is best, and it's core.

If you need junctions (which is the CompSci name, not "quantum"),
there's Perl6::Junction, for Perl5, which is simpler than
Quantum::Superpositions. Of course a script with the word
"superposition" in it, is way cooler.

It's actually useful for many things bigger than finding an element in a list.

Ran
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl

Reply via email to