[ic] Re: Little puzzle for Perl gurus

interchange-users@icdevgroup.org interchange-users@icdevgroup.org
Tue Sep 17 07:52:04 2002


marc.brevoort writes: 

> Hello, 
> 
> Sorry, this is more of a Perl issue than Interchange, 
> but I'm stumped here.  
> 
> The following gives me the result I expected: 
> 
> ##########################################
> sub do_order_action { 
>         my $page=""; 
> 
>         my ($ordernumber,$orderline,%subref,%CGI)=@_;
>         my @keysar=keys %subref;
>         foreach my $ky (@keysar) {$page.=$ky;} 
> 
>         my $comment=$CGI->{"comment_$orderline"};
>         return $page."... subref{hello}=$subref{hello}, comment=$comment";
> } 
> 
> do_order_action($CGI->{order},$line,%ref2sub,%CGI);
> ########################################## 
> 
> Output of the function is: 
> 
> pending_cancelledpending_packingpending_backorderbyehello... 
> ref2sub{hello}=CODE(0x92837ac), comment= 
> 
> After swapping the last two subroutine parameters both
> in the sub and the call to it, the function outputs: 
> 
> ... ref2sub{hello}=, comment=    
> 
> ##########################################
> sub do_order_action { 
>         my $page=""; 
> 
>         my ($ordernumber,$orderline,%CGI,%subref)=@_;
>         my @keysar=keys %subref;
>         foreach my $ky (@keysar) {$page.=$ky;} 
> 
>         my $comment=$CGI->{"comment_$orderline"};
>         return $page."... subref{hello}=$subref{hello}, comment=$comment";
> } 
> 
> do_order_action($CGI->{order},$line,%CGI,%ref2sub);
> ########################################## 
> 
> Although things seem to work OK in the first version, 
> I think it's a bit creepy to not understand why swapping 
> the parameters makes a difference. What am I missing?

It makes no sense to have two hashes in the parameter list.
The first one will consume all remaining arguments.
You need to pass references to hashes. 

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.