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

Re: DBI select ids to @ids

by mifflin (Curate)
on Aug 10, 2005 at 05:38 UTC ( [id://482519]=note: print w/replies, xml ) Need Help??


in reply to DBI select ids to @ids

how about
@ids = @{$dbh->selectcol_arrayref('select id from table where foo > 42 +', { Columns => [1]})};
update

tomazos is right, you can get rid of the Columns if you are only selecting one column
@ids = @{$dbh->selectcol_arrayref('select id from table where foo > 42 +')};

Replies are listed 'Best First'.
Re^2: DBI select ids to @ids
by tomazos (Deacon) on Aug 10, 2005 at 05:47 UTC
    If this works, and the manual says it defaults to one, you can drop the \%attr column and just write @ids = @{$dbh->selectcol_arrayref('select id from table where foo > 42')};

    Why isn't there a $dbh->selectcol_array? There is a $dbh->selectrow_array. Thats weird.

    It should be just:

    @ids = $dbh->selectcol_array('select id from items where foo > 42'); +# SHOULD WORK BUT WRONG

    Or am I missing something?

    -Andrew.


    Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com
      Why no selectcol_array?
      I'm not sure. You could always email Tim Bunce and ask him.
      However, dereferencing an array reference is easy. I really don't see a need for it.
      Personally, I wouldn't dereference it into an array. You're not showing how your are using the @ids array but if you need to pass it around in your code, say as a parameter to another sub, you will probably want it as a reference anyway.
        I agree that wrapping the whole call in @{} isn't hard, however amongst a large chunk of code its easy to mentally parse the brackets incorrectly, or confuse them with end of block delimiters.

        I don't like passing things by reference unless either (A) the sub is going to modify it, or (B) it is so big that it is an efficiency concern. This is because the subroutine might modify it accidentally. Passing by value helps to isolate a bug to a smaller scope (or if the accidental modification doesn't effect the functionality of the sub - avoids it completely).

        Plus its hard to keep track of what is a reference and what isn't, so I try to keep everything lexical and dereferenced to take advantage of the cleaner syntax.

        -Andrew


        Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 16:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found