CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [chrislas] More array issues....: Edit Log



Zhris
Enthusiast

Aug 2, 2013, 7:16 AM


Views: 4783
Re: [chrislas] More array issues....


Code
my @array = ( 1 ); 

print scalar @array . "\n"; # returns the number of elements in the array

#print @array . "\n"; # does the same as above
my $count = @array;
print $count . "\n";


print $#array . "\n"; # returns the last elements subscript


output:

Code
1 
1
0


Edit: my mistake. Never do "print @array", since print is a function and will take each element of @array as arguments. Just so happened I used 1 for an array element.

Chris


(This post was edited by Zhris on Aug 2, 2013, 7:28 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Aug 2, 2013, 7:22 AM
Post edited by Zhris (Enthusiast) on Aug 2, 2013, 7:24 AM
Post edited by Zhris (Enthusiast) on Aug 2, 2013, 7:28 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives