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

Re: Perl script for the post processing of one CSV file

by tybalt89 (Monsignor)
on Oct 03, 2019 at 14:58 UTC ( #11107010=note: print w/replies, xml ) Need Help??


in reply to Perl script for the post processing of one CSV file

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11106985 use warnings; <DATA>; my @sums = (0) x 10; print "Number", ' ' x 18, map(" pat$_", 0 .. 9), "\n"; while( <DATA> ) { s/(?<=,(0|1),)(0|1)/ ($1 ^ 0 ^ $2) * 0.5 /ge; s/Q,1/Q,0/; my @values = (split /,|\n/)[-10 .. -1]; $sums[$_] += $values[$_] for 0 .. 9; s/Q/Q /; s/,([\d.]+)/ sprintf " %-4g", $1 /ge; print; } print my $pound = "#" x 78 . "\n"; printf "SUM Of weights " . " %-4g" x 10 . "\n", @sums; print $pound; __DATA__ PATTERN,pat0,pat1,pat2,pat3,pat4,pat5,pat6,pat7,pat8,pat9 U_TOP_LOGIC/ipre_reg_0/Q,0,0,1,1,0,0,1,1,0,0 U_TOP_LOGIC/ipre_reg_6/Q,1,1,0,0,1,1,0,0,1,1 U_TOP_LOGIC/pre_reck_1/Q,1,1,0,1,1,0,0,1,1,0 U_TOP_LOGIC/pre_reg_10/Q,0,1,0,1,1,0,0,1,1,1 U_TOP_LOGIC/pre_reg_11/Q,0,0,1,0,1,0,0,1,0,1

Outputs:

Number pat0 pat1 pat2 pat3 pat4 pat5 pat6 pat7 pat8 +pat9 U_TOP_LOGIC/ipre_reg_0/Q 0 0 0.5 0 0.5 0 0.5 0 0.5 + 0 U_TOP_LOGIC/ipre_reg_6/Q 0 0 0.5 0 0.5 0 0.5 0 0.5 + 0 U_TOP_LOGIC/pre_reck_1/Q 0 0 0.5 0.5 0 0.5 0 0.5 0 + 0.5 U_TOP_LOGIC/pre_reg_10/Q 0 0.5 0.5 0.5 0 0.5 0 0.5 0 + 0 U_TOP_LOGIC/pre_reg_11/Q 0 0 0.5 0.5 0.5 0.5 0 0.5 0.5 + 0.5 ###################################################################### +######## SUM Of weights 0 0.5 2.5 1.5 1.5 1.5 1 1.5 1.5 + 1 ###################################################################### +########

Some alignments have been tweaked, and a math error fixed.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2023-09-28 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?