G'day Kshitij,
This seemed like an interesting problem to get the mental juices flowing on a Sunday morning, so here's my take on it.
I split the problem into two discrete areas, processing the metadata (before the "---" line) and the pin data (after the "---" line) separately:
if ($meta) { ... } else { ... }
I didn't know if the ']', on a line by itself, was part of the PINS data or a sentinel indicating the end of it. I used 'VecAddr' as the sentinel: you may want to change that. Also, the PINS lines containing a '[' or ']' were different lengths to the other lines: I don't know if that's significant.
Anyway, here's the code:
#!/usr/bin/env perl use strict; use warnings; my $meta = 1; my $pin_meta = 1; my @pins; while (<DATA>) { chomp; next unless /\S/; if ($meta) { if (0 == index $_, '-') { $meta = 0; next; } else { if ($pin_meta) { if (/^\s*VecAddr/) { $pin_meta = 0; } else { my @chars = map { /[[\]]/ ? '' : $_ } split //, (/(\S+)\s*$/)[0]; $pins[$_] .= $chars[$_] for 0 .. $#chars; } } } } else { my ($cycle, $pin_str) = (split)[3,4]; my @pin_str_chars = split //, $pin_str; for (0 .. $#pin_str_chars) { next unless $pin_str_chars[$_] =~ /[hl]/; print "$cycle $pins[$_] $pin_str_chars[$_]\n"; } } } __DATA__ PINS PPPPPPPPPPPPPPP DDDDDDDDDDDEEEE [[[[[[[[[[[[[[[[ 198765432105432 0]]]]]]]]]]]]]]] ] + + + + VecAddr RptCnt VmemAddr Cycle + ------------------------------- ------ -------- ----- ---------------- +---------------- Pat6_Scan_comp_at_speed_m:24791 1 6156500 25701 .......h........ +................ Pat6_Scan_comp_at_speed_m:24884 1 6156593 25794 .h....h......... +................ Pat6_Scan_comp_at_speed_m:24891 1 6156600 25801 ...h.....h...... +................ Pat6_Scan_comp_at_speed_m:26759 1 6158468 27689 ................ +................ Pat6_Scan_comp_at_speed_m:29196 1 6160905 30160 ................ +................ Pat6_Scan_comp_at_speed_m:30671 1 6162380 31650 ....h.h......... +................ Pat6_Scan_comp_at_speed_m:30982 1 6162691 31966 .....hl......... +................ Pat6_Scan_comp_at_speed_m:30985 1 6162694 31969 .....h.......... +................ Pat6_Scan_comp_at_speed_m:30986 1 6162695 31970 .....l.......... +................
As you can see, I've only used enough of your PINS lines for a representative sample (unless I've missed something important in the omitted lines). For future reference, unless a lot of input data is necessary to describe the problem in full, please consider trimming it to a representative subset. Here's the output from that script:
25701 PD3 h 25794 PD9 h 25794 PD4 h 25801 PD7 h 25801 PD1 h 31650 PD6 h 31650 PD4 h 31966 PD5 h 31966 PD4 l 31969 PD5 h 31970 PD5 l
Your PINS data is oddly ordered: leading alphabetics are ascending and trailing numerics are descending. My 2nd and 3rd lines are in a different order to your minimal output description: you may need to add some sorting.
— Ken
In reply to Re: Need help in getting a perl script for below logic
by kcott
in thread Need help in getting a perl script for below logic
by kshitij
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |