Try but beware of off-by-1 errors in the lengths and gaps

#!/usr/bin/perl use strict; my $outfile = 'file2.txt'; open OUT,'>',$outfile or die "Could not open $outfile : $!"; my $sum_len = 0; my $sum_gap = 0; my $def; my $end; while (<DATA>){ if (/TIFF[^\d]+(\d+)\.\.(\d+)/g){ # gaps if (defined $end){ my $gap = $1 - $end; $sum_gap += $gap; printf "%5d to %5d = %5d gap\n",$end,$1,$gap; } # lengths my $len = $2 - $1; $sum_len += $len; printf "%5d to %5d = %5d\n",$1,$2,$len; $end = $2; $def = ''; } elsif (/def="([^"]+)/){ (undef,$def) = split ':',$1; } elsif (/pattern="([^"]+)/){ printf OUT ">%s\n%s\n",$def,$1 if $def; } } close OUT; printf " Sum = %5d %5d\n",$sum_len,$sum_gap; __DATA__ XXXXXXXXXX YYYYYYYY TIFF 1..203 /def="Z/AA:XGproxy1" /pattern="gdgdfn6N6" TIFF trans(256..298) /def="Z/AA:ZYprompt5" /pattern="HbgREV5ehe757gAH" TIFF trans(303..323) /pattern="hfftvt&&jdgY=)" XXXXXXXX YYYYYYYY
poj

In reply to Re: Extract length sum from columns and print pattern into another file by poj
in thread Extract length sum from columns and print pattern into another file by rebkirl

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.