Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I want to count how many cities are listed so the above would have 6 as the count. My attempt below gives me a count of 1. Please advise how I can do it correctly??san francisco; oakland; new york city; boston; miami; detroit;
my $filename = 'myname.txt'; my $ct = 0; open FILE, $filename || "$!"; while(<FILE>) { chomp; my @arr = split /;/, $_; $ct++ } print $ct; close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Count of split data
by petdance (Parson) on Jan 12, 2007 at 15:15 UTC | |
|
Re: Count of split data
by brian_d_foy (Abbot) on Jan 12, 2007 at 15:37 UTC | |
|
Re: Count of split data
by davorg (Chancellor) on Jan 12, 2007 at 15:16 UTC | |
by Anonymous Monk on Jan 12, 2007 at 15:29 UTC | |
|
Re: Count of split data
by eff_i_g (Curate) on Jan 12, 2007 at 15:42 UTC | |
|
Re: Count of split data
by Joost (Canon) on Jan 12, 2007 at 15:16 UTC | |
|
Re: Count of split data
by jwkrahn (Abbot) on Jan 12, 2007 at 15:43 UTC |