(e-mail address removed) wrote in @o13g2000cwo.googlegroups.com:
Well, that seems to have got me about 98% of the way there. Thanks.
However, I still have a problem.
#!/user/bin/perl
use Text:
arseWords;
I guess I should have been more obvious. I would have used Text::CSV_XS
Consider the word 'comma' in comma separated to be a placeholder for
things like pipe, semi-colon, dash etc etc.
When you construct the object, specify what you want to be interpreted
as quote and escape characters etc. Then parse (see the parse method)
your input line by line, look at the number of fields. Record the line
number if the number of fields does not match what you were expecting.
This can't be more than 20 lines or so including use strict and use
warnings.
Post a sample of your data along with the code if you run into problems.
Put the data in the __DATA__ section of your script.
As for your script:
use strict;
use warnings;
missing.
No need to declare these variables in this scope.
use constant EXPECTED_FIELDS => 15;
Please see perldoc perlvar for the $. variable.
my $errCount = 0;
$file="test.txt";
my $file = shift;
$file ||= 'test.txt';
open file or die "Cannot open $file for read:$!";
Are you trying to take advantage of:
If EXPR is omitted, the scalar variable of the same name as
the FILEHANDLE contains the filename. (Note that lexical
variables--those declared with "my"--will not work for this
purpose; so if you're using "my", specify EXPR in your call
to open.)
I do have a feeling that this might be error prone, and I personally
prefer:
open my $fh, '<', $file or die "Cannot open $file: $!";
while(<file>)
{
$rownum++;
You want to use $. here.
chomp;
@fields = quotewords("~", 0, $_);
if ($#fields != $fldcnt) {
@fields in scalar context would return the number of elements in
@fields. That would be a more natural comparison. This also means the
constant I defined above should have been 16 rather than 15. I am going
to leave it that way, however. That is for you to fix.
Sinan.