cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:
Something seems counterintuitive about using $# with array refs:
my @array = (1,2,3,4,5,6,7); print "scalar co print "array last index - $#array\n"; my $arrayref = [1,2,3,4,5,6]; print "arrayref last index - $#$arrayref\n";
Why does this work? The syntax looks wrong to me?
cLive ;-)
update - looking at the array in scalar context makes it easier to see, but it still feels weird to me:
print "array scalar context - ".@array."\n"; print "arrayref scalar context - ".@$arrayref."\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: last index of array ref...
by borisz (Canon) on Apr 02, 2005 at 00:02 UTC | |
|
Re: last index of array ref... (4 rules)
by tye (Sage) on Apr 02, 2005 at 03:37 UTC | |
|
Re: last index of array ref...
by Roy Johnson (Monsignor) on Apr 01, 2005 at 23:55 UTC | |
|
Re: last index of array ref...
by ikegami (Patriarch) on Apr 02, 2005 at 00:29 UTC | |
|
Re: last index of array ref...
by brian_d_foy (Abbot) on Apr 02, 2005 at 02:31 UTC | |
|
Re: last index of array ref...
by ysth (Canon) on Apr 02, 2005 at 01:17 UTC | |
|
Re: last index of array ref...
by Anonymous Monk on Apr 02, 2005 at 06:47 UTC |