Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Having to specify $_

by Aristotle (Chancellor)
on Dec 09, 2002 at 09:36 UTC ( [id://218484]=note: print w/replies, xml ) Need Help??


in reply to Having to specify $_

sub collect (&@) { collect( $_[0]->() || return @_[1 .. $#_] ) } my @results = collect { $sth->fetchrow_hashref };

:^)

Of course, what you really want to do is use one of the fetchall methods - if your result matrices are typically large, the function call overhead for repeated fetchrows is significant.

Update: I can't believe noone called me on my massive stupidity. Anyway, this one will actually work. (Ampersand call form is intended.)

sub collect (&) { ($_[0]->() || return), &collect; } my @results = collect { $sth->fetchrow_hashref };

Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found