Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: prob w/ gatekeeper subroutine

by toolic (Bishop)
on Sep 29, 2010 at 15:53 UTC ( [id://862638]=note: print w/replies, xml ) Need Help??


in reply to prob w/ gatekeeper subroutine

It always sets $x to 'fail' for me, probably because I do not populate the hash. You should show a complete code example that any of us can run: how you call your sub, how you know if it passes or fails, how you initialize your hash. Also, tell us what you enter on the keyboard once you run it.

Replies are listed 'Best First'.
Re^2: prob w/ gatekeeper subroutine
by weglarz (Novice) on Sep 29, 2010 at 16:16 UTC

    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.

      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().

      (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://862638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found