[ic] PREFIX-exec bar_link (Was: coordinated searches including a profile?)

Mike Heins mikeh@minivend.com
Mon, 20 Nov 2000 10:59:29 -0500


Quoting Doug Alcorn (doug@lathi.net):
> I see some code in the interchange base dir catalog_before.cfg.  Does
> the PREFIX-exec tag just execute some arbitrary pre-defined
> subroutine? If so, that is good to know.

Yes, that is it. It can be pre-defined by Sub, or defined in the page
with 

    [PREFIX-sub sub_name]
	    CODE
    [/PREFIX-sub]

Both are much faster than using [calc|perl|PREFIX-calc] [/calc|perl|PREFIX-calc]
as the code is only compiled once (and only one Safe object need be generated).

> I'm looking at the code for
> bar_link and don't understand what all gets passed in.  I assume that
> [PREFIX-exec bar_link]area[/PREFIX-exec] passes 'area' as the first
> argument.  What is the rest?  From the bar_link code, it looks like
> some kind of array.  Can someone point me to the documentation for
> PREFIX-exec?  I've looked on the page titled "Looping tags and
> Sub-tags" with no success.

There are no docs published yet. Basically, the container text is
$_[0], the row returned from the search (all mv_return_fields) is
the array reference passed as $_[1]. So if you did 

    [query list=1 sql="
			SELECT sku, price, description
	     		FROM   products
			WHERE category = 'pliers'
		"]
	[sql-sub my_sub]
	    my ($scalar, $ary) = @_;
	    my $el = scalar @$ary;
	    my $ptr = $my_sub_count++;
	    return "inc $scalar, pointer $ptr, elements $el, price $ary->[1]\n";
	[/sql-sub]
	[sql-exec my_sub][sql-increment][/sql-exec]
    [/query]

it would be equivalent to 

    my_sub('1', ['os28062', '24.99', 'Electricians Plier Set'] );

followed by 

    my_sub('2', ['os28065', '18.99', 'Mechanics Pliers']);

and would return:

	inc 1, pointer 0, elements 3, price 24.99
	inc 2, pointer 1, elements 3, price 18.99

You could have as easily defined my_sub in catalog.cfg with Sub.

I will be producing a "Tips and Tricks" soon that is pointed toward speeding
up slow search pages with this and similar techniques.

-- 
Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH  45056
phone +1.513.523.7621 fax 7501 <heins@akopia.com>

If you think nobody cares if you're alive, try missing a couple of
car payments.  -- Earl Wilson