This is discussed on page 95 of 'Perl Cookbook' as a way to grow or
truncate arrays. It may be useful if you know how big an array will
grow, but are adding values piecemeal (and so perl is spending time
allocating a little chunks of memory many times instead of one big chunk
once). Here are the results I have from a one liner:

-----
% perl -e '@a=(0,1,2,3,4);print"@a $#a\n";$#a=2;print"@a
$#a\n";$#a=12;print"@a $#a\n";'
0 1 2 3 4 4
0 1 2 2
0 1 2           12
% 
-----

So it looks like I can't get the values back (5.002 on Solaris).

Troy

Patrick McCabe wrote:
> 
> I get a syntax error using @#ITEMS.  However, $#ITEMS does equal 2 (in your
> example).
> 
> $#array is the index of the last element in the array.  It is documented, I
> have seen it many times, I just can't seem to find it right now.  I think it
> was more useful in the past when you could set the starting index of arrays
> to something other than zero.  I think you still can, but its discouraged.
> I promptly forgot how to do that because it seems like such a bad idea.
> 
> Patrick McCabe
> 
> ----- Original Message -----
> From: Phil Plumbo <psp at printwareinc.com>
> To: <tclug-list at mn-linux.org>
> Sent: Friday, July 14, 2000 3:24 PM
> Subject: [TCLUG:19613] [OT] perl boogage?
> 
> > I ran across a curiosity in a perl program today, which can be explained
> > like so:
> >
> >  @ITEMS = (0, 1, 2);
> >  print @#ITEMS;                # prints "2";
> >
> >
> > So if you wedge a '#' into an array name, it means "the length of the
> array,
> > less 1" (Oh, of course!). The guy was using it as a loop limit.
> >
> > I couldn't find anything on this in any of the perl books I own... is this
> a
> > documented feature of the language, or just a fetid schbat of boogage?
> >
> > To me, it looks suspiciously like a fetid schbat of boogage.
> >
> > Phil Plumbo.
> >
> > Or, perhaps, a turgid wad of hell-snot.
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tclug-list-unsubscribe at mn-linux.org
> > For additional commands, e-mail: tclug-list-help at mn-linux.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe at mn-linux.org
> For additional commands, e-mail: tclug-list-help at mn-linux.org

-- 
Troy Johnson   mailto:john1536 at tc.umn.edu   http://umn.edu/~john1536/
As with the Christian religion, the worst advertisement for Socialism
is its adherents.
	-- George Orwell

---------------------------------------------------------------------
To unsubscribe, e-mail: tclug-list-unsubscribe at mn-linux.org
For additional commands, e-mail: tclug-list-help at mn-linux.org