Here's another tybalt89-ish solution:

c:\@Work\Perl\monks>perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; use constant W => 0.5; ;; my @records = ( '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', ); ;; my $rx_transition = qr{ (?<= 1) 0 | (?<= 0) 1 }xms; ;; my @pat = (0); for my $record (@records) { my (undef, $trans) = split m{ \d/Q, }xms, $record, 2; $trans =~ tr/01//cd; $pat[ $-[0] ]++ while $trans =~ m{ $rx_transition }xmsg; } $_ *= W for @pat; ;; is_deeply \@pat, [ 0, 0.5, 2.5, 1.5, 1.5, 1.5, 1, 1.5, 1.5, 1, ], 'weighted'; ;; done_testing; " ok 1 - weighted 1..1 ok 2 - no warnings 1..2

Update: You can simplify the code slightly by changing the
    $pat[ $-[0] ]++ while $trans =~ m{ $rx_transition }xmsg;
statement to
    $pat[ $-[0] ] += W while $trans =~ m{ $rx_transition }xmsg;
and getting rid of the
    $_ *= W for @pat;
post-loop weighting fixup statement altogether – but this code might be slightly slower.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Perl script for the post processing of one CSV file by AnomalousMonk
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.