[VPM] array refs driving me nuts
Carl B. Constantine
cconstan at csc.UVic.CA
Thu May 20 17:15:26 CDT 2004
*On Thu May 20, 2004 at 02:16:44PM -0700, Peter Scott (Peter at PSDT.com) wrote:
> >
> >@array = somefuncreturningarrayvalues();
> >
> >foo(\@array)
> >
> >sub foo {
> > my $arrayRef = @_;
>
> Left hand side = scalar.
> Right hand side = array.
>
> Therefore right hand side is in scalar context, and therefore $arrayRef
> will be set to the number of elements in @_.
yes.
> > bar($arrayRef);
> >}
> >
> >sub bar {
> > my $array = @_;
> >
> > print "Array Values: @$array\n";
> >}
> >ARRAY(HEXADDRESS)
>
> No, it should be a run time error:
>
> Can't use string ("1") as an ARRAY ref while "strict refs" in use at - line
> 12.
>
> Without strict, there will be nothing printed in place of @$array.
I do have strict turned on. I use it in all my perl code. But I was
getting a value out as above. What happened, is I used a different form
at one point (I think tired $$arrayRef first, then realized I should be
using @$arrayRef) and forgot to restart the daemon that used the library
I modified.
Anyway, works now.
--
Carl B. Constantine University of Victoria
Programmer Analyst http://www.csc.uvic.ca
UNIX System Administrator Victoria, BC, Canada
cconstan at csc.uvic.ca ELW B206, 721-8766
More information about the Victoria-pm
mailing list