Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: My excessive and redundant code<333

by bobf (Monsignor)
on Jun 23, 2005 at 04:07 UTC ( [id://469285]=note: print w/replies, xml ) Need Help??


in reply to My excessive and redundant code<333

If it works and it is readable, I wouldn't be too concerned about a few for loops. That said, I'd probably do two things: use hash slices (see perldata) instead of all of the individual $data{key} = $_->key; statements, and pull the guts of the for ( @info ) loop into a subroutine (since you use it twice). For example (untested):

for ( @info ) { push( @loop_data, get_info( $_ ) ); } sub get_info { my ( $info ) = @_; my $sth = $obj->DBI->Replies->sql_count; $sth->execute( $info->id ); my $info->count = ( $sth->fetchrow_array )[0]; my @keys = qw( author content title id date count ); my %data; @data{ @keys } = @$info{ @keys }; return \%data; }

Note: I changed $r to $info->count to clean up the hash slice. Update: Corrected $count to $info->count.

HTH, and congrats on getting it working. That's the first step. :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-03-19 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found