On 11/21/07, AndrewMcHorney <[EMAIL PROTECTED]> wrote:

> Can someone the reasoning why it is technically correct that when
> extracting a scalar item from an array that one must use
> $array_name[$index] instead of @array_name[$index] ?

Reasoning don't come in cans. :-)

When one codes as you did, the perldiag manpage opines:

    You've used an array slice (indicated by @) to select a single
    element of an array.  Generally it's better to ask for a scalar
    value (indicated by $).  The difference is that $foo[&bar] always
    behaves like a scalar, both when assigning to it and when evaluating
    its argument, while @foo[&bar] behaves like a list when you assign
    to it, and provides a list context to its subscript, which can do
    weird things if you're expecting only one subscript.

In other words, it's a matter of context. The sigil tells Perl (and
everyone else) whether you mean singular or plural, and it matters
which you mean. The difference in meaning is akin to that between
"Moving pianos is dangerous" and "Moving pianos are dangerous".

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to