in reply to Re^7: Class::DBI::AbstractSearch and SpeedyCGI
in thread Class::DBI::AbstractSearch and SpeedyCGI

It looks like an obscure case of list context biting you. Take a look at the warnings about \(@foo) in the perlref man page to see what I mean. Maybe your code is using the return value in a list context in the third spot? I would probably throw in some wantarray() checks to see if that's the difference, and maybe break out the debugger.

Replies are listed 'Best First'.
Re^9: Class::DBI::AbstractSearch and SpeedyCGI
by zigdon (Deacon) on Oct 05, 2005 at 04:38 UTC
    Very interesting (and I'll try to see how this applies here) - but why would it only hit on the 3rd iteration, but not the first two? In all cases it was an arrayref with a single element?

    -- zigdon

      Does the code where you call this do it exactly the same every time? There may be something subtle that changes it to list context on the third one. Can you show that part?
        The code is exactly the same, afaict. Here's the relevant code (note, it's ugly, most of it written before I know much perl).
        script.pl: opendir(DIR, $MyApp::Conf::SUBMITROOT) or die "Can't read dir: $!"; foreach (grep /^\d+(?:-\d+)?\.\d+$|^[\-\w]+\.\d+(?:\.jpg)?$|^set\.\d ++(?:-\d+)?\.\d+\.jpg$/, readdir DIR) { $h = {}; $h->{File} = $_; if (/^(\d+(?:-\d+)?)\.(\d+)$/) { ... } elsif (/^set\.(\d+(-\d+)?).(\d+)\.jpg$/) { # this is the case we +'re hitting $h->{Set} = $1; $h->{Set} .= "-1" unless $2; $h->{Timestamp} = $3; $h->{Pic} = 1; my $curpic = $db->GetSetPictures({SetID => $h->{Set}, PicID => 0 +}); $h->{New} = not keys %$curpic; } else { warn "Unknown file: $_"; next; } ---- in the $db object: sub GetSetPictures { my $self = shift; my ($param) = @_; croak "Bad params" unless exists $param->{SetID}; $param->{Self} = "/inv/sets/$param->{SetID}" unless exists $param->{ +Self}; my ($setinfo) = $self->GetSetInfo({Set => $param->{SetID}}); ... sub GetSetInfo { my $self = shift; my ($param) = @_; my %where; if (exists $param->{Set}) { if ($param->{Set} eq '*') { ... } else { if ($param->{Set} =~ /-\d/) { $where{ID} = $param->{Set}; # this is our case in all 3 itera +tions } else { ... } } } else { ... } my @res = MyApp::Sets->search_where(%where); # Class::DBI object wi +th the AbstractSearch plugin ...

        -- zigdon