http://www.perlmonks.org?node_id=862857


in reply to Re^2: prob w/ gatekeeper subroutine
in thread prob w/ gatekeeper subroutine

Well, I don't want to write your assignment answer for you, so I'll give you some different code to ponder a while that may help answer some of your questions.

use strict; use warnings; main (); # Only to ensure no global variables are used - look ma, no v +ariables sub main { my ($dogName, $color) = getDogData (); print "The $color dog's name is $dogName\n"; ($dogName, $color) = getDogData (3); print "The $color dog's name is $dogName\n"; } sub getDogData { my ($select) = @_; my @names = qw(woof k9 fred max); my @colors = qw(spotted white black brown); $select = rand (@names) if ! defined $select; return $names[$select], $colors[$select]; }

Prints:

The black dog's name is fred The brown dog's name is max

Please note that using strictures is not something you do when you have time, it is something you do to save time! Strictures tell you you have done something wrong early and can save huge amounts of time that would otherwise be spent poking around in the dark after black beetles with your eyes closed.

Update: In a follow up question weglarz asked 'What does the "qw" in "my @names = qw(woof k9 fred max);" do?'. See Quote-Like Operators in perlop for a description of Perl's various quote operators like qw.

True laziness is hard work