K
kspecial
Hey, i've got some code here that i've been having problems with, I
have crunched my brain and have resorted to this very place. For some
reason the variable @logins in the following code is being undefined
when there is absolutely nothing that is using @logins in such a way
that it would be undefined, the two functions are out of a lot longer
bit of code but I have put them together here in such a manor that you
can run the following code yourself as a file and get an eye to what's
going on, please excuse any bad syntax, unless it's having to do with
something i've done wrong that causes this problem. Here is the code:
--- CODE ---
@logins = ('K-sPecial perl.freak o (kspecial)');
logout_user(\@logins, "K-sPecial",
"d41d8cd98f00b204e9800998ecf8427e");
sub logout_user {
my ($logins, $name, $pass) = @_;
print "Logins ($logins) in logout_user: @$logins\r\n";
foreach (@$logins) {
if (m/^\s*$name\s+/i) {
#my $rname = get_rname($logins, "$name", ' ',
1);
my $md5 = ub_value ("$rname", 1);
print "Now logins ($logins) in logout_user:
@$logins\r\n";
print "Got $rname and $name then $md5 and
$pass\r\n";
if ("$pass" eq "$md5") {
#my $return = del_login($logins,
"$name");
return ($return);
}
}
return(0);
}
}
sub ub_value {
my ($user, @values) = @_;
#$user = rem_re($user);
my $userline;
open (FH, "<fool.txt") or return (undef);
while (<FH>) {
$userline = $_ if m/^$user:/i;
}
close(FH);
print "Userline is $userline";
if ($userline) {
my @results;
foreach(@values) {
push(@results, (split(':', "$userline"))[$_]);
}
print "Gots the @results\r\n";
return ("$results[0]") if scalar(@values) == 1;
return("@results");
}
else {
print "returning 0\r\n";
return(0);
}
}
--- END CODE ---
So i'm going to run that code exactly as is and show you it's output:
--- OUTPUT ---
kspecial@xzziroz:~$ perl borked.pl
Logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
(kspecial)
Userline is returning 0
Now logins (ARRAY(0x814490c)) in logout_user:
Got and K-sPecial then 0 and d41d8cd98f00b204e9800998ecf8427e
--- END OUTPUT ---
Look! @logins is completely being undefined with no apparent reason!
Now try taking out the call to ub_value ( my $md5 = ub_value
("$rname", 1); ) now @logins is fine. It prints this:
--- OUTPUT ---
kspecial@xzziroz:~$ perl borked.pl
Logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
(kspecial)
Now logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
(kspecial)
Got and K-sPecial then and d41d8cd98f00b204e9800998ecf8427e
--- END OUTPUT ---
Just as it should... now i'm not very good with the perl debugger but
I did manage to get a glimpse at what was happening, at the user
level.
Here is the debugging:
--- DEBUGGING ---
main::ub_value(borked.pl:24): my ($user, @values) = @_;
DB<3> s
main::ub_value(borked.pl:26): my $userline;
DB<3> p "@logins"
K-sPecial perl.freak o (kspecial)
DB<4> s
main::ub_value(borked.pl:27): open (FH, "<fool.txt") or
return (undef);
DB<4> p "@logins"
K-sPecial perl.freak o (kspecial)
DB<5> s
main::ub_value(borked.pl:28): while (<FH>) {
DB<5> p "@logins"
K-sPecial perl.freak o (kspecial)
DB<6> s
main::ub_value(borked.pl:29): $userline = $_ if
m/^$user:/i;
DB<6> p "@logins"
kspecial:d41d8cd98f00b204e9800998ecf8427e
w:-1:::
DB<7> s
main::ub_value(borked.pl:29): $userline = $_ if
m/^$user:/i;
DB<7> p "@logins"
xemp:c4ca4238a0b923820dcc509a6f75849b
:1000:::
DB<8> s
main::ub_value(borked.pl:29): $userline = $_ if
m/^$user:/i;
DB<8> p "@logins"
coprime:c81e728d9d4c2f636f067f89cc14862c:v:9999:::
--- END DEBUGGING ---
Of course that's assuming your fool.txt looks like this:
--- START fool.txt ---
kspecial:d41d8cd98f00b204e9800998ecf8427e
w:-1:::
xemp:c4ca4238a0b923820dcc509a6f75849b
:1000:::
coprime:c81e728d9d4c2f636f067f89cc14862c:v:9999:::
--- END fool.txt ---
Oddly the line " $userline = $_ if m/^$user:/i " is assigning $_ to
@logins on every loop......I'm gonig to also send this same message
using 'perlbug' if i'm able to.
--K-sPecial
have crunched my brain and have resorted to this very place. For some
reason the variable @logins in the following code is being undefined
when there is absolutely nothing that is using @logins in such a way
that it would be undefined, the two functions are out of a lot longer
bit of code but I have put them together here in such a manor that you
can run the following code yourself as a file and get an eye to what's
going on, please excuse any bad syntax, unless it's having to do with
something i've done wrong that causes this problem. Here is the code:
--- CODE ---
@logins = ('K-sPecial perl.freak o (kspecial)');
logout_user(\@logins, "K-sPecial",
"d41d8cd98f00b204e9800998ecf8427e");
sub logout_user {
my ($logins, $name, $pass) = @_;
print "Logins ($logins) in logout_user: @$logins\r\n";
foreach (@$logins) {
if (m/^\s*$name\s+/i) {
#my $rname = get_rname($logins, "$name", ' ',
1);
my $md5 = ub_value ("$rname", 1);
print "Now logins ($logins) in logout_user:
@$logins\r\n";
print "Got $rname and $name then $md5 and
$pass\r\n";
if ("$pass" eq "$md5") {
#my $return = del_login($logins,
"$name");
return ($return);
}
}
return(0);
}
}
sub ub_value {
my ($user, @values) = @_;
#$user = rem_re($user);
my $userline;
open (FH, "<fool.txt") or return (undef);
while (<FH>) {
$userline = $_ if m/^$user:/i;
}
close(FH);
print "Userline is $userline";
if ($userline) {
my @results;
foreach(@values) {
push(@results, (split(':', "$userline"))[$_]);
}
print "Gots the @results\r\n";
return ("$results[0]") if scalar(@values) == 1;
return("@results");
}
else {
print "returning 0\r\n";
return(0);
}
}
--- END CODE ---
So i'm going to run that code exactly as is and show you it's output:
--- OUTPUT ---
kspecial@xzziroz:~$ perl borked.pl
Logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
(kspecial)
Userline is returning 0
Now logins (ARRAY(0x814490c)) in logout_user:
Got and K-sPecial then 0 and d41d8cd98f00b204e9800998ecf8427e
--- END OUTPUT ---
Look! @logins is completely being undefined with no apparent reason!
Now try taking out the call to ub_value ( my $md5 = ub_value
("$rname", 1); ) now @logins is fine. It prints this:
--- OUTPUT ---
kspecial@xzziroz:~$ perl borked.pl
Logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
(kspecial)
Now logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
(kspecial)
Got and K-sPecial then and d41d8cd98f00b204e9800998ecf8427e
--- END OUTPUT ---
Just as it should... now i'm not very good with the perl debugger but
I did manage to get a glimpse at what was happening, at the user
level.
Here is the debugging:
--- DEBUGGING ---
main::ub_value(borked.pl:24): my ($user, @values) = @_;
DB<3> s
main::ub_value(borked.pl:26): my $userline;
DB<3> p "@logins"
K-sPecial perl.freak o (kspecial)
DB<4> s
main::ub_value(borked.pl:27): open (FH, "<fool.txt") or
return (undef);
DB<4> p "@logins"
K-sPecial perl.freak o (kspecial)
DB<5> s
main::ub_value(borked.pl:28): while (<FH>) {
DB<5> p "@logins"
K-sPecial perl.freak o (kspecial)
DB<6> s
main::ub_value(borked.pl:29): $userline = $_ if
m/^$user:/i;
DB<6> p "@logins"
kspecial:d41d8cd98f00b204e9800998ecf8427e
DB<7> s
main::ub_value(borked.pl:29): $userline = $_ if
m/^$user:/i;
DB<7> p "@logins"
xemp:c4ca4238a0b923820dcc509a6f75849b
DB<8> s
main::ub_value(borked.pl:29): $userline = $_ if
m/^$user:/i;
DB<8> p "@logins"
coprime:c81e728d9d4c2f636f067f89cc14862c:v:9999:::
--- END DEBUGGING ---
Of course that's assuming your fool.txt looks like this:
--- START fool.txt ---
kspecial:d41d8cd98f00b204e9800998ecf8427e
xemp:c4ca4238a0b923820dcc509a6f75849b
coprime:c81e728d9d4c2f636f067f89cc14862c:v:9999:::
--- END fool.txt ---
Oddly the line " $userline = $_ if m/^$user:/i " is assigning $_ to
@logins on every loop......I'm gonig to also send this same message
using 'perlbug' if i'm able to.
--K-sPecial