Re: lvalue hash slice

Richard Clamp <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
On Tue, Sep 30, 2003 at 11:07:24PM +0300, Gaal Yahas wrote:
> I like hash slices:
> 
>     ($one, $two, $three) = @hash{ qw/aaa bbb ccc/ };
> 
> Sadly, this doesn't work as an lvalue:
> 
>     @hash{ qw/aaa bbb ccc/ } = ($one, $two, $three);        # WRONG

Um.  Sure it does:

% perl -MData::Dumper -e '$one = 1; $two = 2; $three = 3; \
     @hash{ qw/aaa bbb ccc/ } = ($one, $two, $three); \
     print Dumper \%hash'
$VAR1 = {
          'bbb' => 2,
          'aaa' => 1,
          'ccc' => 3
        };

-- 
Richard Clamp <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.