Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/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.


In reply to Re: Perl script for the post processing of one CSV file by tybalt89
in thread Perl script for the post processing of one CSV file by kshitij

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-24 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found