in reply to Comparing the individual characters in two strings to find their differences

Shouldn't it look like:

my ($additionaltext) = $sth->fetchrow_array;

or

my @data = $sth->fetchrow_array; my ($additionaltext) = @data;

? fetchrow_array() returns array, not scalar.

Replies are listed 'Best First'.
Re^2: Comparing the individual characters in two strings to find their differences
by ikegami (Patriarch) on Apr 03, 2008 at 07:51 UTC

    Definitely. I once made the same mistake as the OP and it still worked, but one shouldn't count on that. There's no guarantee that it'll work with different database drivers, different versions of the driver being used, or even from call to call.

    Aside from that, the OP should consider using selectrow_array since only the first row is fetched.

    my $sth = $db->prepare('SELECT * FROM milton1'); $sth->execute(); my ($additionaltext) = $sth->fetchrow_array; $sth->finish;

    becomes

    my ($additionaltext) = $db->selectrow_array('SELECT * FROM milton1');

    I'm also annoyed by the inconsistency between $db and $sth. Use "h" for both or for neither. Actually, use "h" for both to be consistent with all the documentation out there.

      ikegami++ Pretty useful and I didn't know that syntax. Every day I'm learning something new :)