Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Subroutine Even/Odd

by marquezc329 (Scribe)
on Oct 04, 2012 at 18:20 UTC ( #997283=note: print w/ replies, xml ) Need Help??


in reply to Subroutine Even/Odd

Here's what I came up with.

#!/usr/bin/perl use strict; use warnings; sub num { my $array = shift; my $func = shift; return grep {$_%2==0} @$array if ($func eq 'even'); return grep {$_%2!=0} @$array if ($func eq 'odd'); } my @a = 1..10; my @b = (447..460, 2000..2012); print num(\@a, 'even'), "\n"; print num(\@b, 'odd'), "\n";
I'm a beginner so please inform me if this is an inefficient/misguided way of accomplishing this.


Comment on Re: Subroutine Even/Odd
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2015-07-30 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls