Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: DBI Style Inquiry

by Eily (Parson)
on Jun 27, 2013 at 08:51 UTC ( #1040961=note: print w/replies, xml ) Need Help??

in reply to DBI Style Inquiry

You could "name" your first parameter by assigning its value to a lexical. Like chomp(my $param = $_[0]);. But that's not really much change, and that's up to you.

However, there is a problem with your code. The "return" statement exits the sub immediatly, and everything below that point is skipped. Besides, you assign the result of fetchrow_array() to an array that you never use (you could have written return $sth->fetchrow_array();). If you want the end of the sub to be run, you should have something like:

sub get_loc { ... my @loc = $sth->fetchrow_array(); $sth->finish; $dbh->disconnect or die "Error disconnecting: $DBI::errstr\n"; return @loc; }

Replies are listed 'Best First'.
Re^2: DBI Style Inquiry
by edict (Novice) on Jun 27, 2013 at 09:10 UTC
    Concerning the return statement, apparently it is commonly known that the subroutines exit there but I was ignorant about that fact (I've never taken a programming class, to be honest). Thank you for your input!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040961]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2017-12-11 16:34 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (308 votes). Check out past polls.