G'day kshitij,

"I am not able to link the regexp logic to match it based on the output file"

That shouldn't matter as "regexp logic" is not required here. You can do this with Perl's string-handling functions; which are quite likely to be faster than a regex solution (test with Benchmark).

This code:

#!/usr/bin/env perl use strict; use warnings; my $scan_data_found = 0; my @pins; my $format = "%-7s %-6s %-7s %s\n"; my @scan_line_data; printf $format, qw{pattern offset pin_num H/L}; while (<DATA>) { chomp; next unless length; if ($scan_data_found) { if (@scan_line_data) { my $caret_pos = 0; while (1) { $caret_pos = index $_, '^', $caret_pos; last if $caret_pos == -1; printf $format, @scan_line_data[0,1], join('', map $_->[$caret_pos], @pins), $scan_line_data[2][$caret_pos]; ++$caret_pos; } @scan_line_data = (); } else { push @scan_line_data, ((split ' ')[0,1], [split //]); } } else { if (0 == index $_, 'pattern') { $scan_data_found = 1; } else { push @pins, [split //]; } } } __DATA__ p p p p p Pin Numbers 3 2 1 8 9 1 2 3 4 5 pattern offset scan1 2965 H L H L H ^ scan2 2200 L H H L H ^ scan3 1100 H L L L L ^ scan4 1500 L L H H H ^ scan5 2800 H H L H H ^ ^

Produces this output:

pattern offset pin_num H/L scan1 2965 p13 H scan2 2200 p22 H scan3 1100 p22 L scan4 1500 p13 H scan5 2800 p22 H scan5 2800 p95 H

The split function does take a regex as its first argument; however, that's not the line matching regex you were talking about.

— Ken


In reply to Re: Perl script to match a regexp in the prior line and other multiple lines by kcott
in thread Perl script to match a regexp in the prior line and other multiple lines 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.