Gossamer Forum
Home : General : Perl Programming :

Variables Not Holding the Info

Quote Reply
Variables Not Holding the Info
 Hi I am having trouble with my variables holding the information from a file that I opened. It seems that it will only hold the information for 1 time. This is what i have for the code.
Code:
sub login2 {

$username = "$input{'username'}";

if (-e("$memberdir/$username.txt") ){
open(FILE,"$memberdir/$username.txt");
@settings = <FILE>;
close(FILE);

$settings[0] =~ s/[\n\r]//g;
$settings[1] =~ s/[\n\r]//g;
$gotpos = "$settings[1]"; #what position the user is
if ( $settings[0] eq "$input{'password'}") { &redirect; }
else { print "$txt{'2'}"; }
}else{ print "$txt{1}"; }

}

sub redirect {
if ( $gotpos eq "Leader" ) { &ldrindex; }
elsif ( $gotpos eq "Clan Recruiter" ) { &crindex; }
elsif ( $gotpos eq "Squad Leader" ) { &slindex; }
elsif ( $gotpos eq "Squad Recruiter" ) { &srindex; }
elsif ( $gotpos eq "Private" ) { &prindex; }
else { print "$txt{3}"; }
}


It will read the $gotpos that i have there perfectly and it works but when i try using $gotpos after I logged in the information that $gotpos held is no longer there. So when I try to verify a person position from $gotpos it will just put a blank spot so no one can go to any of the other pages in my script. I am calling the variable $gotpos on a different sub routine within a different file if that has anything to do with it.

Thanks
Kurt
Quote Reply
Re: [snowdude14] Variables Not Holding the Info In reply to
I'm not sure. Have you tried passing the value through the sub routine?

i.e;

Code:
&redirect($gotpos);

sub redirect {

my $gotpos = shift;

if ( $gotpos eq "Leader" ) { &ldrindex; }
elsif ( $gotpos eq "Clan Recruiter" ) { &crindex; }
elsif ( $gotpos eq "Squad Leader" ) { &slindex; }
elsif ( $gotpos eq "Squad Recruiter" ) { &srindex; }
elsif ( $gotpos eq "Private" ) { &prindex; }
else { print "$txt{3}"; }

}

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [snowdude14] Variables Not Holding the Info In reply to
It looks like a 'scoping' problem, though you haven't explicitly declared the variable with a 'my' declaration.

Andy's suggestion should work, or you could write a function to return the value

HTH Ax
Quote Reply
Re: [snowdude14] Variables Not Holding the Info In reply to
Using strict coding will cure these sort of headaches :)