[ic] Re: Syntax Question on Using Cart in UserTags (Perl)

interchange-users@icdevgroup.org interchange-users@icdevgroup.org
Fri Sep 27 12:30:01 2002


C.B. Currier writes: 

>> C.B. Currier writes: 
>>
>> > Trying to do a loop through a cart inorder to do some SQL lookups.
>> > Having a problem with the fact that I believe the cart is being
>> passed in
>> > but for what ever reason I cannot reference the array properly.
>> > Any suggestions on the below mentioned code is greatly appreciated.
>> > BTW: I am not necessarily getting an error, just not log string being
>> > returned.
>> >
>> > C.B.
>> >
>> > Code:
>> >
>> > UserTag test_calc Routine <<EOF
>> > sub {
>> > 	my $itmcount = 0;
>> > 	my $itmlst = "";
>> > 	my $item = $Carts->{main};
>> > 	foreach (@$item){
>> > 		$itmcount++;
>> >             $itmlst.= $item->{code}; 
>>
>> $item is the cart array, the item itself is $_. Good penalty
>> for bad variable naming. 
>>
>> Bye
>>     Racke
> 
> I understand what you are saying however the Documentation suggests that
> infact it is not $item which is the array but $Items.  

$Items and $Carts->{main} are the same thing. 

In a use defined
> routine I gather that I am dealing with a perl environment. Originally I
> tried to formalize this byt using the [perl][/perl] tags but to no avail.
> SO... I tried to pass the $Carts->{main} to a new variable. I am not passing
> any variables on the call of this user tag so I would suspect that the $_
> does not apply? 

Perl uses $_ as loop variable if you don't supply one. Your code
would be more clear like that: 

$cart = $Carts->{main};
for my $item (@$cart) {
   $itmcount++;
   $itmlst .= $item->{code};
} 

Anyway, that is boring C style. In Perl, you can write: 

$itmcount = @$cart;
$itmlst = join('', map {$_->{code}} @$cart); 

> Correct? Therefore within a perl environment within
> interchange dont I need to reference the proper Perl like tags? That is waht
> I have been doing. As per the Interchange documentation. I wrote straight
> perl code that worked in regular perl but having the need to reference the
> cart I have run into this problem.

A good Perl text book might help :-) 

Ciao
    Racke 

-- 
Prolific Interchange Consulting (Excellent German Quality !).
Take a look at Materialboerse (http://www.materialboerse.de/), WITT
(http://www.witt-weiden.de/), Boxmover (http://shop.boxmover.ch/) or
Passionshop (http://www.passionshop.com/racke). Need a shop ? Contact us.