RustyShackelford has asked for the wisdom of the Perl Monks concerning the following question:
The code outputs:#!/usr/bin/perl use strict; my $count=0; my @cp_op = "111 222 333"; foreach my $line (@cp_op) #splits each line of the array { print "$line\n"; $count ++; } print "$count\n";
Why does count only increment once instead of 3 times, once for each line??? Please help111 222 333 1
20091208 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counter in foreach loop
by jwkrahn (Abbot) on Dec 05, 2009 at 22:47 UTC | |
|
Re: Counter in foreach loop
by AnomalousMonk (Archbishop) on Dec 05, 2009 at 23:18 UTC | |
|
Re: Counter in foreach loop
by biohisham (Priest) on Dec 06, 2009 at 01:21 UTC | |
|
Re: Counter in foreach loop
by Bloodnok (Vicar) on Dec 06, 2009 at 00:54 UTC |