[Edinburgh-pm] help again with lists

Julian Turnbull jules-turnbull at zetnet.co.uk
Mon Mar 19 11:53:32 PDT 2007

Chris Benson wrote:

>On Sun, Mar 18, 2007 at 05:04:48PM +0000, Andrew Smith wrote:
>>Having,  I think fully understood list assignments with () and qw, I've 
>>moved on to dabbling  with lists in code.
>>Why can I not refer to the number of elements in @words1 using  $words1 
>>in lines 6 & 7 in the attached test program  ?
>The clue is:
>	Global symbol "$words1" requires explicit package name at - line 4.
>Which is: 
>	my $words1count=$words1;
>$words1 hasn't been mentioned anywhere, you need to do:
>	my $words1count = @words1;
>And that enables the rest of the program to work:
>There are 5 elements  in list @words1
>Best wishes
Just to spell it out a little more, the scalar $words1 has no connection 
(apart from spelling) with the list @words1, or even with that list's 
elements $words1[0], $words1[1], etc.  However, using the list @words1 
in a scalar context happens to give the value you are looking for, the 
number of elements in the list.


More information about the Edinburgh-pm mailing list