perlguru22 has asked for the wisdom of the Perl Monks concerning the following question:
Hey,guys I have to create the subroutine that will take the even and odd numbers from an array and print them out but I Haven't been able to combine the 2 into 1 this is what I have
I know there's an easier way to do it but I always complicate my program I would appreciate any help I can get.sub even { my @a = @_; foreach $number(@a) { if($number%2==1) { $number = $_; } print "$number"; } print " = Even numbers\n"; } sub odd { my @a = @_; foreach my$number (@a) { if($number%2==0) { $number = $_; } print "$number"; } print "= odd numbers\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Subroutine Even/Odd
by tobyink (Canon) on Oct 04, 2012 at 07:36 UTC | |
Re: Subroutine Even/Odd
by johngg (Canon) on Oct 04, 2012 at 08:11 UTC | |
Re: Subroutine Even/Odd
by 2teez (Vicar) on Oct 04, 2012 at 08:16 UTC | |
Re: Subroutine Even/Odd
by clueless newbie (Curate) on Oct 04, 2012 at 14:32 UTC | |
Re: Subroutine Even/Odd
by marquezc329 (Scribe) on Oct 04, 2012 at 18:20 UTC |
Back to
Seekers of Perl Wisdom