Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

idiom for ( 1 < $foo < 10) ?

by tenya (Beadle)
on May 18, 2001 at 05:57 UTC ( [id://81414]=perlquestion: print w/replies, xml ) Need Help??

tenya has asked for the wisdom of the Perl Monks concerning the following question:

Is there an idiom for this:
(1 < $foo < 10) or die;

Edit 2001-05-18 by mirod: changed the title from "idiom for" to "idiom for ( 1 < $foo < 10) ?"

Replies are listed 'Best First'.
Re: idiom for
by jynx (Priest) on May 18, 2001 at 06:20 UTC

    A common way to do it? How about this:
    (1 < $foo && $foo < 10) or die "$foo not in range:";
    Did you have something else in mind?

    HTH,
    jynx

Re: idiom for
by MeowChow (Vicar) on May 18, 2001 at 07:35 UTC
    This topic was recently discussed in this thread.

    Oh, you want an idiom? How about...

    grep int $foo == $_, 1..9 or die;
    Just kidding :-)

    And yes, I know, this screws up the 1 < x part...

       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
Re: idiom for
by damian1301 (Curate) on May 18, 2001 at 06:27 UTC
    or if you want to do something if that results to true, you can do this:

    (1 < $foo && $foo < 10) ? do_stuff($foo) : die("nooo!");
    UPDATE:Spaced it out for clarity...and because I am/was bored.

    Tiptoeing up to a Perl hacker.
    Dave AKA damian

Re: idiom for
by clemburg (Curate) on May 18, 2001 at 12:56 UTC

    Repost from earlier thread:

    sub is_ordered_according_to { my ($binary_predicate, @values) = @_; if (@values < 3) { return $binary_predicate->(@values); } else { return $binary_predicate->($values[0], $values[1]) && is_ordered_according_to($binary_predicate, @values[1..$#values]); } } sub less_than { return shift() < shift(); } print is_ordered_according_to(\&less_than, 1, 2, 3, 4, 5, 6) ? "yes" : "no", "\n" ; print is_ordered_according_to(\&less_than, 3, 2, 1, 4, 5, 6) ? "yes" : "no", "\n" ; print is_ordered_according_to(\&less_than, 1, 2, 3, 4, 6, 5) ? "yes" : "no", "\n" ;

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found