At 08:48 PM 4/16/01 +0100, Nic LAWRENCE wrote:
>All becomes clear. Thanks.

BTW, I used the wrong section from perldiag below; I should have picked the 
part on array slices for your example.  But it's practically identical 
except for [] instead of {} :-)

> > -----Original Message-----
> > From: Peter Scott [mailto:[EMAIL PROTECTED]]
> > Sent: 16 April 2001 8:47
> > To: Nic LAWRENCE; [EMAIL PROTECTED]
> > Subject: Re: use strict;
> >
> >
> > At 08:37 PM 4/16/01 +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]?
> >
> > You're unintentionally using a slice, thereby imposing a list
> > context where
> > you'd probably expect a scalar context.
> >
> > >If there's an faq which tells me WHY then
> > >if someone could point me to that I'd be very happy. ;-)
> >
> > Inserting "use diagnostics" or running the message through splain, or
> > looking the message up in perldiag, would reveal the reason:
> >
> > Scalar value @%s{%s} better written as $%s{%s}
> >
> > (W) You've used a hash slice (indicated by @) to select a single
> > element of
> > a hash.  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.
> >
> >
> >
> > --
> > Peter Scott
> > Pacific Systems Design Technologies
> >

--
Peter Scott
Pacific Systems Design Technologies

Reply via email to