in reply to DBI::CSV using a variable to request columns

select * from newCsv.csv WHERE gender ='male' AND genotype ='a'

As an aside: Please specify the column names instead of select *. Specifying column names protects against column additions, subtractions, and changes in column order. Furthermore, it is self-documenting. "select *" ought to be relegated to exists() and ad hoc queries.

  • Comment on Re: DBI::CSV using a variable to request columns

Replies are listed 'Best First'.
Re^2: DBI::CSV using a variable to request columns
by Sandy_Bio_Perl (Beadle) on May 20, 2016 at 14:42 UTC

    Thank you chacham. The select * is working without any problems. I will paste the headings somewhere below for reference. My problem is that I cannot store the headings "sid = $row->{sid} \tgender = $row->{gender}\n"; into the variable $columns and then use that variable to describe the columns I wish to see in the output

    Headings

    <code>sid name genotype gender tgroup <\code>

    Many thanks for responding

Re^2: DBI::CSV using a variable to request columns
by LanX (Saint) on May 22, 2016 at 15:34 UTC
    I think we had this discussion already...

    > against column additions, subtractions, and changes

    I wonder how is this relevant if one uses ->fetchrow_hashref ?

    (like the OP does)

    update

    Re^2: Database connection issue

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      I think we had this discussion already...

      I do not see how that changes the advice. There are ways to avoid some of the errors (disregarding if that is good practice), but the self-documenting part is still true.

      I wonder how is this relevant

      It isn't. Hence the introductory, "As an aside".

        > There are ways to avoid some of the errors (disregarding if that is good practice), but the self-documenting part is still true.

        Very generic ...

        In this sense: DRY is also a good practice! :)

        And less generic:

        The best practice would be a programming style/ SQL abstraction which allows defining the fields just once and automatically checks a table's integrity at compile-time.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!