Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: validating file with perl

by Anonymous Monk
on Jul 16, 2013 at 22:25 UTC ( #1044670=note: print w/ replies, xml ) Need Help??


in reply to validating file with perl

Something like this:

use strict; use warnings; my %data; <DATA>; while(<DATA>){ chomp; next if/^\s*$/; my ($key, $value) = split; push @{$data{$key}},$value; } my $counter; for(keys %data){ for(@{$data{$_}}){ ++$counter if $_ == 1 or $_ == 3; } print $_,' a good file',$/ if $counter == 2; } __DATA__ field1 field2 3-2000/7.48 1 3-2000/7.48 2 3-2000/7.48 2 3-2000/7.48 2 3-2000/7.48 2 3-2000/7.48 2 3-2000/7.48 2 3-2000/7.48 3 4-0000/8.40 2 4-0000/8.40 2 4-0000/8.40 2 4-0000/8.40 2 4-0000/8.40 2 4-0000/8.40 2 4-0000/8.40 3


Comment on Re: validating file with perl
Download Code
Re^2: validating file with perl
by Cristoforo (Deacon) on Jul 16, 2013 at 22:47 UTC
    What if there were two 1's and no 3's or vice versa. Then $counter == 2 and the file wouldn't be good.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2015-07-07 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls