SPUG: scalar(@array)

Patterson, David S (David) davidpa at lucent.com
Thu Apr 13 19:17:34 CDT 2000


Hmmm...  Very perplexing...  Running the following program

  @array = (aa, bb, cc, dd, ee);
  print @array, '  ', scalar (@array), "\n";
  undef $array[3];
  print @array, '  ', scalar (@array), "\n";
  print @array, '  ', $#array, "\n";

gives the following output:

  aabbccddee  5
  aabbccee  5
  aabbccee  4

What does this mean?  Are there 4 elements or 5?

I thought I read once that the underlying implementation of arrays in Perl
was just another hash table.
Is this true?  Did it change between Perl 4 and Perl 5?

		"The first 90% of the project takes 90% of the time, and the
last 10% takes the other 90%..."

> 	David Patterson
> 	Software Engineer
> 	Lucent Technologies *
> 	6464 185th Ave NE
> 	Redmond, WA  98052-6736
> 	425-558-8008 x 2172
		888-501-4835 Pgr
> 	davidpa at lucent.com
> 
> 
> 
> -----Original Message-----
> From:	R. Christianson [SMTP:ryannn at u.washington.edu]
> Sent:	Thursday, April 13, 2000 4:19 PM
> To:	Jeremy Mates
> Cc:	'SPUG'
> Subject:	Re: SPUG: scalar(@array)
> 
> What about doing $#array?
> 
>     Ryan Christianson
> 
> 
> On Thu, 13 Apr 2000, Jeremy Mates wrote:
> 
> > The count you were probably expecting to see can be gained by doing
> > something like:
> > 
> > for ( @array ) {
> >     $count++ if defined;
> > }
> > print $count, "\n";
> > 
> > -- 
> > Jeremy Mates                           (206) 221-4714   Fax: 685-7301
> > Systems Administrator                  K353-B, Health Sciences Center
> > http://www.mbt.washington.edu/         Box 357730
> > University of Washington               Seattle, WA, 98195
> > 
> > 
> >  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> -
> >      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
> >  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
> >  SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or
> unsubscribe
> >            Email to majordomo at pm.org: "action" spug-list your_address
> > 
> > 
> > 
> 
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>  SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
>            Email to majordomo at pm.org: "action" spug-list your_address
> 

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
           Email to majordomo at pm.org: "action" spug-list your_address





More information about the spug-list mailing list