Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Subroutine Even/Odd

by clueless newbie (Chaplain)
on Oct 04, 2012 at 14:32 UTC ( #997241=note: print w/replies, xml ) Need Help??

in reply to Subroutine Even/Odd

Do not turn the following in unless you're prepared to explain things.

#!/usr/bin/perl use strict; use warnings; # Effect a "join" with ", " local $"=', ';#" # Use the baby cart so we can call even / odd within quotes to exploit + $" print "@{[even(1,2,3,4)]} are even\n while @{[odd(1,2,3,4)]} are odd\n +"; exit; # Note the use of prototypes so we can pass the list and the desired r +emainder without flattening sub EvenOrOdd (\@$) { my ($numbers,$remainder)=@_; return grep { $_ % 2 == $remainder } @$numbers; }; sub even { EvenOrOdd(@_,0); }; sub odd { EvenOrOdd(@_,1); };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997241]
[karlgoethebier]: My perltidy adds a semicolon after .... How can i avoid this?
[LanX]: ellipse aka ... aka yadda yadda is a new command
[LanX]: sopw!
[1nickt]: Sorry kgb can't help there, not a perltidy user.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2017-11-18 18:19 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (277 votes). Check out past polls.