pelagic has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks
does anybody have an idea why the first attempt to merge the hashes does not work while the second does?
@run{$runtype}{$pid}{keys %message} = values %message; # Error: Can't use subscript on hash slice while ( my ($k,$v) = each(%message) ) { $run{$runtype}{$pid}{$k} = $v; } # works fine

pelagic

Replies are listed 'Best First'.
Re: merge/add hash to hash-slice
by broquaint (Abbot) on Jun 08, 2004 at 11:51 UTC
    You've got to dereference at the appropriate level e.g
    @{ $run{$runtype}{$pid} }{keys %message} = values %message;
    See. perlreftut and tye's References quick reference for more info on dereferencing complex structures.
    HTH

    _________
    broquaint

      of course ... and thanks a lot!

      pelagic
Re: merge/add hash to hash-slice
by BrowserUk (Patriarch) on Jun 08, 2004 at 11:56 UTC

    Try

    @{ $run{$runtype}{$pid} }{keys %message} = values %message;

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail