On Mon, Apr 16, 2001 at 08:37:09PM +0100, Nic LAWRENCE wrote:
: Thought I'd have a go at securing one of my scripts after Ray's question
: about security. When using "strict", I am told the following:
: 
: Scalar value @views_keys[$k] better written as $views_keys[$k] at
: ./newremote2.pl line 327.
: Scalar value @_[0] better written as $_[0] at ./newremote2.pl line 342.
: Scalar value @cview_cams[0] better written as $cview_cams[0] at
: ./newremote2.pl line 346.
: Scalar value @_[0] better written as $_[0] at ./newremote2.pl line 359.
: 
: I'm curious to know why for example something like @cview_cams[0] would be
: better written as $cview_cams[0]? If there's an faq which tells me WHY then
: if someone could point me to that I'd be very happy. ;-)

An array is a list of scalars, thus, when accessing a single element
of an array, you are accessing a scalar value.  It is the same
principle as accessing a single value from a hash, you write it as
'$hash{key}'.  The dollar sign denotes scalar.

@cview_cams[0] is actually called a literal slice, that is, to take a
slice from an array.  But, your slice only consists of a single
element which looks like a scalar to Perl.

In other words, when accessing a single element of an array, remember
that it is a scalar value and use the dollar sign:

$cview_cams[0];

read perlfaq4, the section titled: "What is the difference between
$array[1] and @array[1]?"

Enjoy!

-- 
Casey West

Reply via email to