[VPM] array refs driving me nuts

Peter Scott Peter at PSDT.com
Thu May 20 16:16:44 CDT 2004


At 01:49 PM 5/20/2004, Carl B. Constantine wrote:
>*On Thu May 20, 2004 at 12:21:26PM -0700, Peter Scott (Peter at PSDT.com) wrote:
> > At 12:05 PM 5/20/2004, Carl B. Constantine wrote:
> > This is what happens when I do what you describe:
> >
> > % perl -Mstrict -wl
> > my @array = qw(dog cat bird aardvark);
> > foo(\@array);
> > sub foo {
> >   my $arg = shift;
> >   bar($arg);
> > }
> > sub bar {
> >   my $arrayref = shift;
> >   print "@$arrayref";
> > }
> > ^D
>
>Well, what happens when I do it:
>
>@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 @_.

>     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.


-- 
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
*** New! *** http://www.perlmedic.com/




More information about the Victoria-pm mailing list