James Powell wrote:
> I'm trying to (as you might have guessed) coerce an array
> into a hash. This is from a data structure returned of CGI::Cookie.
So unroll it into an array, use that array to initialise an anonymous hash,
and dereference that anonymous hash.
> I'm sure it's a simple solution... I've been doing too much
> php & c (sniff).
>
> jp
>
>
> I've got
>
> my %cookies = fetch CGI::Cookie;
> my @monkey = @{$cookies{jobsearch1}->{value}}; # works fine
> my %tripitaka = @{$cookies{jobsearch1}->{value}}; # also
> works fine
> # my $boob = @{$cookies{jobsearch1}->{value}}->{d}; #
> gives can't coercearray into hash
$boob = {@{$cookies{jobsearch1}->{value}}}->{d};
Simple, innit? (Took me several tries, though :-))
Or like this:
$hashref = {@{$cookies{jobsearch1}{value}}};
$boob = $hashref->{d};
or like this:
%hash = %{{@{$cookies{jobsearch1}{value}}}};
# who said Perl looks like line noise?
$boob = $hash{d};
Cheers,
Philip