in reply to Count of split data
If you just want to count things you don't need to split the data. Use the transliteration operator (see perlop to replace the semicolons with itself. It returns the count of the number of things it replaced:
my $count = $string =~ tr/;/;/
Sometimes you'll see this without the replacement side, but it does the same thing.
my $count = $string =~ tr/;//
If you apply it to $_, it's a bit shorter since the binding operator disappears:
# my $count = $_ =~ tr/;// # same thing my $count = tr/;//
Now, if you want to do this for a bunch of lines and acculumate the count, just add to what you already have.
my $count = 0; while( <$fh> ) { $count += tr/;// }
If you really want the split to get out the city names though, it's almost the same idea:
my $count = 0; while( <$fh> ) { $count += my @cities = split /;/; }
|
|---|