March 2009 Archives
Hey y’all, I’ve volunteered to teach in the Fedora Classroom this Saturday (7 Mar 2009). The Fedora Classroom is an IRC-based classroom environment.
So, at 3pm MST (22:00 UTC), anyone can participate by logging in to #fedora-classroom on irc.freenode.net and I, fozzmoo, will be doing a 1-hour presentation on Perl basics.
I’ve been digging through old presentations and workshops notes from when I used to do all day Perl workshops at USU for the USU Free Software and Linux Club to see what I can distill down into a 1-hour presentation. If there’s enough interest and response, we’ll see about turning this into a regular thing.
(Ryan Byrd)[http://www.ryanbyrd.net/techramble/] blogged recently with a (programming interview question)[http://www.ryanbyrd.net/techramble/2009/03/03/programming-interview-question-of-the-day/] that I thought I’d take a stab at in Perl.
The question is as follows:
- when passed in a number that is evenly divisible by 3, return “wiz”
- when passed in a number that is evenly divisible by 5, return “bang”
- when passed in a number that is evenly divisible by both 3 and 5, return “wiz bang”
- otherwise, return the number passed in
My solution exploits Perl’s list type to store potential output as a queue of sorts.
sub function {
my $num = shift;
my @output = ();
unless($num % 3) { push @output, "wiz"; }
unless($num % 5 ) { push @output, "bang"; }
if(@output) { return join ' ', @output; }
return $num;
}

