[ic] Perl / Session question

interchange at thedesignpeople.com interchange at thedesignpeople.com
Thu Apr 15 14:39:42 EDT 2004

Peter wrote:

> interchange at thedesignpeople.com wrote:
>> Could someone knowledgable in perl be kind enough to help me out here.
> Not positive about this, but I think I might be able to explain your 
> problem here:
>> I have discovered that this works to manually set the discount:
>>   $Session->{discount} = ({
>>                     'code1' => '199',
>>                     'code2' => '199',
>>                     'code3' => '199'
>>             });
> $session->{discount} expects a scalar, hence the $ in the front.  The 
> right side of the equal sign could be either a scalar (hashref) or an 
> array with one element which is a hashref, since the left side expects a 
> scalar it's interpreted as a hasref rather than an array and it's happy.
>> $Session->{discount} = @arrayval;
> The right side of this can also be interpreted as either a scalar or an 
> array.  since the left side is a scalar it gets the scalar value of the 
> right side which is the number of elements in the array (1).  Hence it's 
> assigning the value 1 to $Session->{discount}.  I don't think this is 
> what you want here.
>> The script dies with the following error:
>> Runtime error: Can't use string ("1") as a HASH ref while "strict 
>> refs" in use at /www/interchange/interchange-5/lib/Vend/Interpolate.pm 
>> line 5151.
> Interchange expects $Session->{discount} to be a hashref, but you just 
> assigned it the value 1 (which is obviously *not* a hashref).  So when 
> Interchange tries to reference a hash from it later on, perl complains 
> and barfs with the above error.
> Peter

Thank you Peter, that makes 100% sense.  After reading your response it 
took me about a minute to get the code working.  I can't belive I didn't 
hit upon it durring my trial and error tests :)  All i needed to do was 
change @arrayval to $hashval.

Thanks again,
Mike Kang

More information about the interchange-users mailing list