in reply to Re: compare two values in perl
in thread compare two values in perl

To add my two cents into this: use fetchrow_hashref

The simple reason is, with an array if you change the SQL statement you need to update the code. This doesn't cause an issue if your only grabbing one line... but what happens when all of a sudden want to get the first name as well so you can say hello afterwards: (note really this code would be best on a multiple reply but in this case it should 'hopefully' be one username only...)

my $p; my ($userid,$firstname); my $sth = $dbh->prepare(q{Select user_id,firsname from user where user +_id = ?}); $sth->execute( $user_name ); while( $p = $sth->fetchrow_hashref ) { $userid = $p->{user_id}; $firstname = $p->{firstname}; } if(defined $username) { print "Hello $firstname, welcome back!"; } else { # display an error message, code somewhere else loginerror($userid); }

--
Even smart people are dumb in most things...