[ic] Perl / Session question

Peter peter at pajamian.dhs.org
Wed Apr 14 21:09:16 EDT 2004


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


More information about the interchange-users mailing list