[ic] Problems using SearchOp

Kevin Walsh kevin at cursor.biz
Wed Jul 5 08:36:34 EDT 2006


"Tim Good" <tim.g at edsd.com> wrote:
> I am trying to create my own op for searching on $somedate
> ge than today.
> Folling directions at:
> http://www.icdevgroup.org/pipermail/interchange-users/2005-A
> pril/042874.html
> Which differ slightly from:
> http://www.icdevgroup.org/interchange-doc-5.2.0/frames/icdat
> abase_32.html
> 
> Interchange: 5.4.1 stable, Perl: Perl 5.8.7 non-threaded
> Here is what I put in my catelog.cfg :
> 
> ## Custom search op for greater than todays date
> ## used to filter auctions which haven't started yet
> ## from search results.
> CodeDef auctionstart SearchOp
> CodeDef auctionstart Routine <<EOR
> sub {
>       my ($self, $i, $pat) = @_;
>       $pat = reverse($pat);
>       $pat = qr($pat)i;
> 
>       return sub {
>               my $itemstart = shift;
>               return ($itemstart ge "2006-07-03 00:00:00");
>       };
> }
>
You don't need the two $pat lines in there, by the way.  They were
useful in the code you copied/pasted but are not used at all in
your code.

On the other hand, you might want to pass your date string in as a
mv_searchspec (se=yourdatestring), and capture that in $pat,
instead of hard-coding the value in your code.

>
> And the error I get is:
> 
>  search error: Limit subroutine creation: Can't use an
> undefined value as an ARRAY reference at
> /usr/local/interchange/lib/Vend/Search.pm line 653.
> 
Try this patch:

*** lib/Vend/Search.pm- Wed Jul  5 12:44:01 2006
--- lib/Vend/Search.pm  Wed Jul  5 13:30:27 2006
***************
*** 649,656 ****
                $c->[$i] =~ tr/ \t//;
                my $o = $c->[$i];
                $c->[$i] = $s->{mv_numeric}[$i]
!                               ? [ @{$numopmap{$o}} ]
!                               : [ @{$stropmap{$o}} ];
                if(! $c->[$i]) {
                        my $r;
                        $c->[$i] = [$r, $o], next
--- 649,656 ----
                $c->[$i] =~ tr/ \t//;
                my $o = $c->[$i];
                $c->[$i] = $s->{mv_numeric}[$i]
!                               ? $numopmap{$o}
!                               : $stropmap{$o};
                if(! $c->[$i]) {
                        my $r;
                        $c->[$i] = [$r, $o], next

The dereference and re-reference seems wasteful to me, and is the
cause of the problem you reported.  If there's a reason for doing
that, and I can't see one, then it can be done later in the code.

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


More information about the interchange-users mailing list