in reply to scalar ref losing it's value?

Why are you first assigning to two variables in a loop, and only use those values after the loop has finished? That way, you'll only ever be using the values set in the last loop.

You probably want to put the rest of the code in the loop body, if the idea is to test all data pairs that were fetched.

Replies are listed 'Best First'.
Re^2: scalar ref losing it's value?
by ikegami (Patriarch) on May 05, 2006 at 07:28 UTC
    You probably want to put the rest of the code in the loop body

    I thought that at first, but then I figured his query returns at most one row. Using a loop to fetch one item is very misleading. He should probably have used

    my $dbpass = $sth->fetch; ($UIDholder, $LNholder) = @{$dbpass}; ...
    or
    my $dbpass = $sth->fetch or die("Bad data. XXX not found\n"); $sth->fetch and die("Bad data. Multiple XXX in table YYY\n"); ($UIDholder, $LNholder) = @{$dbpass}; ...
      Even if so, I wonder what it's supposed to do if he gets more than one row. Now he just ignores every one except for the last. Yours will ignore everything but the first, I think.
        The second snippet checks to make sure one, and only one row is returned. It dies if not.
      actually, i was only trying to get one row back, so thank you for the improved code on accomplishing that....i still get very disordered in my thinking about dealing with arrays...i was trying a few things, and i kept getting back the array ref, rather than the array itself.