in reply to Working out frequency statistics with perl
Apart from that, I wonder if your "readmap" command ever outputs any lines with initial whitespace. If so, your split statement should be:use strict; use warnings;
because that will differ from /\s+/ -- try this snippet to see the difference:@fields = spit " ";
update: To clarify the issue, using "\s+" for splitting will get you into real trouble if the "readmap" output varies in terms of presence/absence of whitespace at the beginning of each line. If the output is consistent in this regard, then using "\s+" is probably not a problem -- you just need to make sure you've counted the field indexes correctly, so that $fields[2] etc really point at what you want them to point at.$_ = " begins with whitespace"; @a = split " "; @b = split /\s+/; print "quoted-space split returns ", scalar @a, " elements\n"; print "\\s+ split returns ", scalar @b, ", first one has length ",leng +th($b[0]),"\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Working out frequency statistics with perl
by wishartz (Beadle) on Jul 16, 2008 at 10:43 UTC | |
by moritz (Cardinal) on Jul 16, 2008 at 11:10 UTC | |
by wishartz (Beadle) on Jul 16, 2008 at 12:48 UTC | |
by jethro (Monsignor) on Jul 16, 2008 at 14:26 UTC |