ravi45722 has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my $row_element = 0; my $col_element = 0; foreach my $col_element (0 .. $max_cols) { foreach $row_element (0 .. $max_rows) { print $row_element; } } print $row_element;
Here in the foreach loop I am changing the value of $row_element. Still its printing zero out of the loop. Why??? I am maintaining scope by initialising at top.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable in a foreach loop
by haukex (Archbishop) on Jul 14, 2016 at 10:50 UTC | |
|
Re: Variable in a foreach loop
by hippo (Archbishop) on Jul 14, 2016 at 11:28 UTC | |
|
Re: Variable in a foreach loop
by perldigious (Priest) on Jul 14, 2016 at 12:50 UTC | |
by haukex (Archbishop) on Jul 14, 2016 at 13:15 UTC | |
by perldigious (Priest) on Jul 14, 2016 at 13:51 UTC | |
|
Re: Variable in a foreach loop
by shadowsong (Pilgrim) on Jul 15, 2016 at 11:12 UTC | |
|
Re: Variable in a foreach loop
by InfiniteSilence (Curate) on Jul 16, 2016 at 18:03 UTC |