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

Re: Subroutine Even/Odd

by tobyink (Abbot)
on Oct 04, 2012 at 07:36 UTC ( #997197=note: print w/replies, xml ) Need Help??

in reply to Subroutine Even/Odd

This construct is weird:

if($number%2==0) { $number = $_; } print "$number";

It works because $_ is initially undef and you never assign to it. It's incredibly fragile though.

Here's how I'd do it...

use 5.010; use List::MoreUtils qw(part); my $numbers = [ 1 .. 10, 211, 1000 ]; my ($evens, $odds) = part { $_ % 2 } @$numbers; say "Even numbers: "; say $_ for @$evens; say "Odd numbers: "; say $_ for @$odds;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997197]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-02-21 13:18 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (309 votes). Check out past polls.