in reply to Re^2: Perl script to match a regexp in the prior line and other multiple lines
in thread Perl script to match a regexp in the prior line and other multiple lines

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11110110 use warnings; $_ = do { local $/; <DATA> }; print " pattern offset pin_num\n"; while( /\^/g ) { my $pre = $`; my ($pattern, $offset) = $pre =~ /^(\S+) +(\S+).*\n(.*)\z/m; my $skip = length $3; printf "%6s%7s%5s%s%s%9s\n", $pattern, $offset, ($pre =~ /^.{$skip}(\w)/gm)[ 0..2, -1] } __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 ^ ^
  • Comment on Re^3: Perl script to match a regexp in the prior line and other multiple lines
  • Download Code