[ic] Array of Hashes

Rick Bragg lists at gmnet.net
Tue May 18 22:08:14 UTC 2010


On Wed, 2010-05-19 at 09:27 +1200, Peter wrote:
> On 19/05/10 08:10, Rick Bragg wrote:
> > Hi,
> > 
> > I want to be able to store an array of hashes in the session, but it
> > seems I am having trouble with this.  My problem is how do I store a
> > hash in the session for later? and how do I access this later on?
> > 
> > i.e. storing:
> > 
> > The array would be something like the following:
> > 
> > [calc]
> > @AoH = (
> >     {  sku => "item_101",  color => "green", },
> >     {  sku => "item_102",  color => "blue", },
> >     {  sku => "item_103", color => "red", },
> >     {  sku => "item_104",  color => "gray", },
> > );
> > $Scratch->{saved_item_hash} = join(' ', @AoH);
> 
> $Scratch->{saved_item_hash} = \@AoH;
> 
> > return;
> > [/calc]
> > 
> > 
> > Then somewhere else on the page access again later somehow with:
> > [calc]
> >   my @AoH = split(' ',$Scratch->{saved_item_hash});
> 
> my @AoH = @{$Scratch->{saved_item_hash}};
> 
> > [/calc]
> > 
> > I know this is wrong, but any ideas or best practice for this?
> 
> That said, from what it looks like you're trying to do, why not just
> save the items in a named shopping cart?
> See:
> http://www.interchange.rtfm.info/icdocs/tags/userdb.html
> http://www.interchange.rtfm.info/icdocs/Interchange_user_database.html#Shopping_carts
> http://www.interchange.rtfm.info/icdocs/Interchange_Perl_objects.html#Carts
> 
> 
> Peter
> 

True, it is more of an "item only breadcrumbs" type of thing for the
last so many "recently viewed items" It gets updated "unshift" on the
fly page, and displays in various places witn an include...  It's easy
enough, for some reason I couldn't think of it today ;)

Thanks!
Rick







More information about the interchange-users mailing list