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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [Alaskan5] Array question: Edit Log

Veteran / Moderator

Jun 10, 2013, 10:57 AM

Views: 1474
Re: [Alaskan5] Array question

To start with, you need to declare $row and $col with the my function.

Second, this line:

for($row = 0; $row < 2; $row++)

is probably wrong, as you probably want $row to takes values from 0 to 2 (including 2), so you probably want to have something like:

for (my $row =0; $row < 3; $row ++)

I would rewrite the sub to something like this, using a better loop construct:

sub get_row()  {  
foreach my $row (0..2) {
foreach my $col (0..2) {
print "$values [$row][$col] \n";

Well, to tell the truth, I would probably not put that code in a subroutine, but if I did, I would pass the array (or an array ref) as an argument to the sub rather than using @values as a global variable.

And remove the print from the last line of your code.

(This post was edited by Laurent_R on Jun 10, 2013, 10:57 AM)

Edit Log:
Post edited by Laurent_R (Veteran) on Jun 10, 2013, 10:57 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