Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Clean Up MySQL Code

by DrManhattan (Chaplain)
on Apr 20, 2003 at 15:31 UTC ( #251831=note: print w/replies, xml ) Need Help??


in reply to Clean Up MySQL Code

You can reduce three of your lines to one by using selectall_arrayref() like so:
my $results = $dbh->selectall_arrayref( "SELECT * FROM shop_items", { Slice => {} } ); foreach my $hash_ref (@$results) { # blah }
If you want to write it as a subroutine, this would work:
sub fetch_data { my $dbh = shift; return $dbh->selectall_arrayref( "SELECT * FROM shop_items", { Slice => {} } ); }
Then you could call it like this:
foreach my $hash_ref (@{&fetch_data($dbh)}) { # blah }

-Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://251831]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2023-12-06 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (30 votes). Check out past polls.

    Notices?