[Catalyst] assigning vars to $c->stash

Matt Lawrence matt.lawrence at ymogen.net
Mon Mar 12 11:58:56 GMT 2007


Carl Franks wrote:
> On 12/03/07, Octavian Rasnita <orasnita at gmail.com> wrote:
>> I have a $hash hash reference and I want to add all its elements to the
>> stash. How can I do this? Do I need to use a loop and assign each 
>> element
>> one by one?
>>
>> I have seen that it is not possible to use $c->stash = $hash;
>
> %{ $c->stash } = ( %{ $c->stash }, %$hash );
> would also work, which combines both hashes.
>
> This is very much a perl references problem - not something cat-specific.
>
> See `perldoc perlref` for more info.
>
I'm a fan of slicing, no need to construct a new hash:

@{$c->stash}{keys %$hash} = values %$hash;

Matt




More information about the Catalyst mailing list