Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: How do I write subs that take bare blocks as args?

by flounder99 (Friar)
on Jun 28, 2002 at 11:34 UTC ( #177991=note: print w/replies, xml ) Need Help??

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

Couldn't this be done with a grep?

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



Replies are listed 'Best First'.
Re: Re: How do I write subs that take bare blocks as args?
by DamnDirtyApe (Curate) on Jun 28, 2002 at 14:49 UTC

    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
      Why so complicated? :)
      if(not grep { $_->price > 1000 } @product_list) { # do stuff }
      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.
        Why so complicated? :)

        And your idea of uncomplicating things is to make them not work as desired?

      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?



        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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://177991]
Corion idly wonders if there is a way to produce ordered .yml files. I want to accept YAML for a configuration file format, but I also want to generate (for debugging/start) a sample configuration file from the current configuration.
[Corion]: Ideally, that configuration file would have some order of the keys, but I'm not sure whether/how YAML supports ordered output.
[Corion]: Basically I have this metadata and generating a purposeful example is much better if the output is ordered in the same way the documentation is ordered

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-01-16 12:00 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (149 votes). Check out past polls.