http://www.perlmonks.org?node_id=178028


in reply to Re: How do I write subs that take bare blocks as args?
in thread How do I write subs that take bare blocks as args?

Hey, good idea! Except, to work the same as my example, it needs to be:

if ( ( grep { $_->price <= 1000 } @product_list ) == @product_list ) { # do stuff }

_______________
D a m n D i r t y A p e
Home Node | Email

Replies are listed 'Best First'.
Re^3: How do I write subs that take bare blocks as args?
by Aristotle (Chancellor) on Jun 28, 2002 at 16:03 UTC
    Why so complicated? :)
    if(not grep { $_->price > 1000 } @product_list) { # do stuff }
    Update:
    my @p = (0,2,4,5,2,5,7,7); print "1: none\n" if not grep { $_ > 1000 } @p; push @p, 1002; print "2: none\n" if not grep { $_ > 1000 } @p; =output 1: none
    ____________
    Makeshifts last the longest.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: How do I write subs that take bare blocks as args?
by flounder99 (Friar) on Jun 28, 2002 at 15:31 UTC
    You are right. In my example the { #do stuff } block will get executed if any of the members of @product_list pass the conditions. You want to know if all members pass.

    IIRC won't perl6 have some kind of any and all builtins?

    --

    flounder

      It will. But Quantum::Superpositions will give them to you now. (Warning: This module is superfreaky.)


      We are using here a powerful strategy of synthesis: wishful thinking. -- The Wizard Book