in reply to Re: MySQL results inserted into Perl variable
in thread MySQL results inserted into Perl variable

The only change that I would make to the foregoing is that I would choose to specify the column-name, not as a bareword, but as a literal string, viz:

... $data->[0]{'field1'};

By far, the most common practice in any case is to let the row of data be returned as a hashref, then to retrieve the fields from it by column-name.   If you feel cozy working with Perl variable-names from that point forward (and there’s certainly something to be said for that ...), that’s easily done.   After retrieving the row as a hashref, do this:

my $field1 = $data->[0]{'field1'};

Replies are listed 'Best First'.
Re^3: MySQL results inserted into Perl variable
by Athanasius (Archbishop) on Jul 09, 2014 at 04:37 UTC
    ... not as a bareword, but as a literal string, ...

    Provided the bareword is a “single identifier” (i.e., something that would be a valid variable name if preceded by the appropriate sigil), Perl parses it as a string literal when it’s used as a hash subscript. From the Camel Book (4th Edition, p. 70):

    As in some shells, you can put braces around the identifier to distinguish it from following alphanumerics: "How ${verb}able!". An identifier within such braces is forced to be a string, as is any single identifier within a hash subscript. For example:

    $days{"Feb"}

    can be written as:

    $days{Feb}

    and the quotes will be assumed. Anything more complicated in the subscript is interpreted as an expression, and then you’d have to put in the quotes...

    (Emphasis added.)

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re^3: MySQL results inserted into Perl variable
by Anonymous Monk on Jul 09, 2014 at 01:29 UTC

    The only change that I would make to the foregoing is that I would choose to specify the column-name, not as a bareword, but as a literal string, viz:

    So you have more to type?

    my $field1 = $data->[0]{'field1'};

    That is not stupid at all , you really should have $field99 instead of that pesky $data array