[ic] Having a UserTag program (causing Internal State Error)

Kevin Walsh kevin at cursor.biz
Tue Jul 6 14:50:15 EDT 2004


the OnE [bicolspice at yahoo.com] wrote:
>
> UserTag attribute_count Interpolate
> UserTag attribute_count Order code attribute
> UserTag attribute_count Routine <<EOF
> 
> sub {
>   my ($code, $attribute) = @_;
>   my $results = $Tag->query(
>                   {
>                   sql => "select $attribute from
> products
>                           where sku = '$code'"
>                   }
>                 );
> 
>   $_ = $results->[0]->[0];
>   my @temp = split(/, */, $_);
>   $Scratch->{attribute_count_debug}  = scalar @temp;
>   return scalar @temp;  #return the number of items }
> EOF
> 
> [snip]
> 
> Unfortunately, the UserTag causes an Internal State error...
> 
> 192.168.1.60 gJJuHYia:192.168.1.60 -
> [06/July/2004:08:41:36 -0400] cpws
> /cgi-bin/cpws/BusinessCards.html Runtime error: Can't
> use string ("") as an ARRAY ref while "strict refs" in
> use at (tag 'attribute_count') line 9.
> 
> 
Firstly, you shouldn't be using $_ in the context you've shown above.
A local variable would be a much better choice.

Secondly, and directly related to your error message, you're not
checking whether your results variable has a value before attempting
to use it as an arrayref.  The following minimal Perl script will
generate the error message you reported:

    use strict;

    my $resultset = '';
    my $foo = $resultset->[0];

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin at cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/



More information about the interchange-users mailing list