Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Checking the Ascendency/Descendency of Numeric Array of Any Size

by dk (Chaplain)
on Mar 23, 2007 at 08:46 UTC ( [id://606190]=note: print w/replies, xml ) Need Help??


in reply to Checking the Ascendency/Descendency of Numeric Array of Any Size

I like List::Util, so for example:
use List::Util qw(reduce); sub is_asc { reduce { (defined($a) and $a < $b) ? $b : undef } @_ } print is_asc(1,2,3,4) ? 1 : 0, "\n"; print is_asc(1,3,2,4) ? 1 : 0, "\n"; 1 0
  • Comment on Re: Checking the Ascendency/Descendency of Numeric Array of Any Size
  • Download Code

Replies are listed 'Best First'.
Re^2: Checking the Ascendency/Descendency of Numeric Array of Any Size
by Eimi Metamorphoumai (Deacon) on Mar 23, 2007 at 15:40 UTC
    But then is_asc(-2,-1,0) comes out false.
      0 is false, undef is also false, but 0 is not undef. is_asc(-2,-1,0) returns 0, not undef.
        But if you use it as was suggested (with a ternop ? 1 : 0), then it still evaluates false. If you're going to write a function, at least put the defined test into the function.
        A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2024-04-23 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found