[ic] Perl / Session question
interchange at thedesignpeople.com
interchange at thedesignpeople.com
Thu Apr 15 14:54:27 EDT 2004
Stefan Hornburg wrote:
> On Wed, 14 Apr 2004 17:42:58 -0700
> "interchange at thedesignpeople.com" <interchange at thedesignpeople.com> wrote:
>
>
>>Could someone knowledgable in perl be kind enough to help me out here.
>>
>>I have discovered that this works to manually set the discount:
>> $Session->{discount} = ({
>> 'code1' => '199',
>> 'code2' => '199',
>> 'code3' => '199'
>> });
>>
>>I thought the following would have the same effect but does not work:
>># create empty array
>>@arrayval = ();
>># create a hash
>>$hashval = {
>> 'code1' => '199',
>> 'code2' => '199',
>> 'code3' => '199'
>> };
>># put the hash into an array
>>push @arrayval, $hashval;
>>
>>$Session->{discount} = @arrayval;
>>
>>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.
>>
>>I'm not sure what this error means.
>>Can someone please explain what I'm doing wrong?
>
>
> $Session->{discount} = $hashval;
>
> Although doing tricks like that are not for the unwary and may break
> on later versions of Interchange.
>
Is this because the datastructure for holding the discounts may change
or for security reasons (e.g. potential for an oursider to set their own
discount methods) or both? I was trying to figure out a dynamic and
easy way to apply a discount to a large number of items without having
to resort to manually inputing the
[discount sku]%s-10[/discount]
for each sku.
What I am doing is putting all the skus in a scratch varaible named for
the particular discount code.
Then I set another scratch variable for the code that the visitor inputs.
In perl i read the skus corresponding to discount code entered and set
the $Session->{discount} to the appropriate value.
I can visualize this working with a database table instead of a scratch
variable to hold the discounts and skus as well.
I realize if the discount mechanism ever changes it will need to change
my code, but since I currently don't see another way to do this (except
for the manual mehtod), i'm kinda stuck.
Regards,
Mike Kang
More information about the interchange-users
mailing list