in reply to 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+(\S+).*\n(.*)\z/m; my $mask = $3 =~ tr//\0/cr . "\xff"; my $column = join '', map +($_ & $mask) =~ tr/\0//dr, split /^/, $pr +e; my ($pin, $hl) = $column =~ /(...).*(.)/; printf "%6s%7s%7s%9s\n", $pattern, $offset, $pin, $hl; } __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 ^ ^
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl script to match a regexp in the prior line and other multiple lines
by kshitij (Sexton) on Dec 15, 2019 at 09:41 UTC | |
by afoken (Chancellor) on Dec 15, 2019 at 17:04 UTC | |
by tybalt89 (Monsignor) on Dec 18, 2019 at 16:27 UTC | |
by Anonymous Monk on Dec 15, 2019 at 09:44 UTC | |
by kshitij (Sexton) on Dec 15, 2019 at 14:31 UTC | |
by AnomalousMonk (Archbishop) on Dec 15, 2019 at 19:14 UTC |