How should I assigned the same value to two different keys in this Perl hash? -
when have 2 data structures meaning same thing, ex:
$c->req->cookies->{app1} = $c->req->cookies->{general}; $c->req->cookies->{app2} = $c->req->cookies->{general};
can write:
( $c->req->cookies->{app1}, $c->req->cookies->{app2} ) = $c->req->cookies->{general};
?
also, can write:
$c->req->cookies->{app1} = $c->req->cookies->{app2 } = $c->req->cookies->{general};
?
the second form possible , people use frequently
$x = $y = $z;
the first form not need. assings value first variable.
($x, $y) = $z;
you need 2 member list on right hand side well:
($x, $y) = ($z) x 2;
update: in case, can use x
operator if methods involved return same values both invocations, otherwise, can use
($x, $y) = map $obj->method, 1, 2;
Comments
Post a Comment