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

Ok, dumb joke. Here is the problem, in Ch 5 of the Llama it is said that this:

@name={"one","two","three"}=("David","Ramsey","Martin");

is a shorter way of writing This:
$name{"one"}="David"; $name{"two"}="Ramsey"; $name{"three"}="Martin";

In my code, copied from the Llama, the second way works but the first (better?) way results in the error:
"Can't modify single ref constructor in scalar assignment."
Am I missing something obvious? I've triple checked my typing...Tried it with unquoted numbers as the values...
TIA
jg

Replies are listed 'Best First'.
Re: I've got my hash slice, actually no I don't...
by VSarkiss (Monsignor) on Sep 24, 2001 at 23:15 UTC

    Just a small typo in your code. It should be: @name{"one","two","three"}=("David","Ramsey","Martin"); More elegant (IMHO) is: @name{qw(one two three)} = qw(David Ramsey Martin);

    HTH

Re: I've got my hash slice, actually no I don't...
by suaveant (Parson) on Sep 24, 2001 at 23:13 UTC
    Should be
    @name{"one","two","three"}=("David","Ramsey","Martin");
    no = after @name... maybe it's a typo... I don't have the llama book...

                    - Ant
                    - Some of my best work - Fish Dinner