in reply to Dereferencing fetchall_arrayref({})

DBI::fetchall_arrayref returns an array of arrays. You need two indexes to dereference a data element. Let your code read,

if ( $data->[0][1] eq "large" ) { #something like this or... $data->[0][1] = uc ( $data->[0][1] ); }
Note that ucase is spelled uc, and does not modify its argument in-place.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Dereferencing fetchall_arrayref({})
by bradcathey (Prior) on Apr 25, 2004 at 20:49 UTC
    Thanks Zaxo, I actually tried the $data[1][0] before the OP and was getting errors. So,I dropped in your code as is, but I still get the "is not an array reference" error. Data Dumper shows:

     $VAR1 = [  {  'title' => 'DRAGONFLY',  'scene' => 'DF'  },  {  'title' => 'HUMMINGBIRD',  'scene' => 'HB'  }  ];
    Any other ideas? And yes, I meant uc, but have been reading up on MySQL functions :-)

    —Brad
    "A little yeast leavens the whole dough."

      Try it with the dereferencing arrow, $data->[0][1]. What you show would apply to an AoA, not a reference to one.

      After Compline,
      Zaxo

      What about something like this?

      my $data; while ($_ = $sth->fetchall_arrayref()) { uc(${$_}{'title'}) if(${$_}{'title'} eq "large"); push @{$data}, $_; }
      --
      b10m

      All code is usually tested, but rarely trusted.
        You fell into the old uc trap. uc returns a value, it doesn't modify in place.


        Dave