Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: My excessive and redundant code<333

by moot (Chaplain)
on Jun 23, 2005 at 02:41 UTC ( [id://469270]=note: print w/replies, xml ) Need Help??


in reply to My excessive and redundant code<333

Would Class::DBI help?

--
Now hiring in Atlanta. /msg moot for details.

  • Comment on Re: My excessive and redundant code<333

Replies are listed 'Best First'.
Re^2: My excessive and redundant code<333
by stonecolddevin (Parson) on Jun 23, 2005 at 02:51 UTC
    I'm using Class::DBI. I just don't know how to skim it down to one call of retrieve or whatever method need be called.
    meh.

      First thing to mind is how you do the same things over and over - and I'm not sure the first thing to my mind is what's coming to your mind. ;-)

      A quick perusal of Class::DBI gives me this thought. First off, it's way easier if you can keep the names the same ... so here we try:

      my @comment_cols = qw/title author thread_id id/; for (@comments) { my %data; @data{@comment_cols} = $_->get(@comment_cols); push @c_data, \%data; }
      Or, if you can't keep them the same:
      my %comment_cols = qw/ c_title title author author id thread_id c_id id /; for (@comments) { my %data; @data{keys %comment_cols} = $_->get(values %comment_cols); push @c_data, \%data; }
      Then push the definition (@comment_cols or %comment_cols) out into a package variable so that it only is created once, and then adding/removing/renaming columns becomes a bit easier. After all that, I also notice that anything that says "for ... push" looks like a "map" to me. So I get:
      @c_data = map { my %data; @data{keys %comment_cols} = $_->get(values %comment_cols); \%data; } @comments;
      Then you can take this loop or map, put it into a subroutine that takes the column list or column map as a reference, takes the input from Class::DBI as another reference, and returns the transformed data as a list of hashes. And then you'll be a long way towards making this easier to deal with, IMO. Although I have to admit, it's not really that bad now. I would just anticipate some column renamings by these steps, just to make things easier on me when I change my mind about the name of a column or something. :-)

        I've been meaning to find a use for map,and here it is!!! fantastic...
        meh.

Log In?
Username:
Password:

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

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

    No recent polls found