Perl Variable Problem?

Nick J

New member
Hi, what I'm attempting in Perl is pretty simple.. I've tried looking for the answer but nothing out there gives a straightforward or seemingly relevant answer to what I need to know (and what I've tried so far doesn't work)

I've declared a variable like so..
$userid;

This variable lives outside of all functions on the code text.. because of this, I assumed that'd make it global to the file but it doesn't seem to work that way

I change the value of this variable in a subroutine
sub changeuserid {
$userid = "fred";
}

Then I try..
print "user id is $userid";

and all I get is "user id is "

I've tried using "our $userid;", and applying "use strict", and both.. so far nothing is working

Quite simply.. how do I make this variable global to this file?

Thanks
 
Back
Top