Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: validating file with perl

by space_monk (Chaplain)
on Jul 17, 2013 at 05:47 UTC ( [id://1044726]=note: print w/replies, xml ) Need Help??


in reply to validating file with perl

Sigh, I go away for a few weeks and see lots of solutions which don't use Text::CSV and their friends. Text::CSV can handle space or tab separated data as well as "normal" comma separated data.

Please do not succumb to the Dark Side, and use the Force of existing CPAN modules properly. :-)

use Text::CSV; my %data; my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attr +ibute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", "test.csv" or die "test.csv: $!"; while ( my $row = $csv->getline( $fh ) ) { my ($key, $value) = @$row; $data{$key} =0 if (!exists $data{$key}); $data{$key} |=1 if ($value == 1); $data{$key} |=2 if ($value == 3); } $csv->eof or $csv->error_diag(); close $fh; foreach my $key (%data) { print "$key invalid\n" if ($data{$key} != 3); }
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1044726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-29 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found