1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use List::Util qw(first);
my $file = 'test.txt';
my %frames_found;
{
open my $fh, '<', $file or die "$file: $!";
# change block separator to have one complete frame
# read per iteration
local $/ = "\nFRAME NAME:";
# read the blocks
while ( my $frame = <$fh> ) {
next if $. == 1; # skip the "header"
chomp $frame; # remove block separator
# get frame name
my ($name) = $frame =~ m{\A [^\(\[]* [\(\[] (\w+) [\)\]] }x;
# skip the frame when no name is given
next if !$name;
# check if user wants to get info about frame. Skip the frame if the
# user didn't mentioned it
next if !first{ $name eq $_ }@ARGV;
# get all signals
my @signals = grep{ $_ }$frame =~ m{^ \s* :+ 0x\d+ (.*?) \r?\n? $}xmg;
my @found;
for my $signal ( @signals ) {
# skip signals that contains "FREI" or "(ID2)"
next if index( $signal, 'FREI' ) != -1;
next if index( $signal, '(ID2)' ) != -1;
# skip signal if it does not contain _FA, or _A,
next if $signal !~ m{ _F?A, }x;
my ($value) = $signal =~ m{ \( ([^\)]+) \) }x;
push @found, $value if $value;
}
$frames_found{$name} = @found ? \@found : 1;
}
close $fh;
}
print Dumper \%frames_found;