Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: prob w/ gatekeeper subroutine

by weglarz (Novice)
on Sep 29, 2010 at 16:16 UTC ( [id://862646]=note: print w/replies, xml ) Need Help??


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

Thanks for the response. I will post the hash and the main part of the code that calls the subroutine. Sorry, should have done this in the first place.

$x = (); %userpass = ('john','ball','tim','super','matt','password','dan','nad3 +2'); &entersys; if($x == "pass") { print("Welcome to the system!\n"); } else { print("That user/password is incorrect\n"); }

I use them as global variables and a global hash so that the subroutines permanently change them.

Replies are listed 'Best First'.
Re^3: prob w/ gatekeeper subroutine
by toolic (Bishop) on Sep 29, 2010 at 16:23 UTC
Re^3: prob w/ gatekeeper subroutine
by rowdog (Curate) on Sep 29, 2010 at 21:58 UTC
    I use them as global variables and a global hash so that the subroutines permanently change them.

    Don't do that. It's called action at a distance and it's considered a bad practice. Instead of modifying a global variable, you should return a value from entersys().

Re^3: prob w/ gatekeeper subroutine
by Anonymous Monk on Sep 29, 2010 at 16:45 UTC
    (The error regarding the check for numerical vs. string equality has been pointed out and was not contained in your original post, so I ignore it in my response.)

    I believe you are encountering a variable scoping issue. Make sure your hash contents are visible to the subroutine (which they aren't unless you assign the correct global scope to the hash variable). The following declaration of the hash inside a naked block will throw an error as the hash is unknown to the subroutine.
    #! /usr/bin/perl -w use strict; { our %hash; $hash{ 1 } = "OK"; &routine; } sub routine { print $hash{ 1 }; }

    Hope this helps.
    Pat

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-24 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found