Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: prob w/ gatekeeper subroutine

by weglarz (Novice)
on Sep 30, 2010 at 15:50 UTC ( #862805=note: print w/replies, xml ) Need Help??

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

Thanks for everyone's responses. I am actually using Perl v 5.8.8. Also, what would I call a subroutine with other than &? I am currently learning to use strict but as this is an assignment, I need to get it to work before the due date and I cannot spend the extra time on learning strict before I have to turn it in. Also, if I were to stop using global variables, how would I change the admin password in this program. At the moment I have a subroutine that changes the global variable $adminpass.

Replies are listed 'Best First'.
Re^3: prob w/ gatekeeper subroutine
by GrandFather (Sage) on Sep 30, 2010 at 21:11 UTC

    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]; }


    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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2020-02-23 08:35 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (102 votes). Check out past polls.