in reply to Idiomize This - Cleanup/Transform

You didn't provide any example data for testing, so I can't guarantee that the following actually works. It does compile though.

my %abbreviations = ( G => 'Green', Y => 'Yellow', R => 'Red', C => 'Checkered', U => 'Unflagged', ); my @cleanups = ( [ position => qr{\+}, undef, 'g' ], # sometimes there is a "+" [ driver => qr{\s*\(R\)$} ], # I don't care if rookie [ best_speed => qr{\+}, undef, 'g' ], # sometimes there is a "+" a +t end [ status => qr{\A\z}, 'Run' ], # not all the series track run, + pit, etc [ status => qr{In Pit}i, 'Pit' ], [ status => qr{Active}i, 'Run' ], [ status => qr{Pace_Laps}i, 'Pace' ], ); sub get_state { my ($self, $contents) = @_; $contents =~ s/\r//g; my %session = (); foreach (split /\n/, $contents) { if (/^ \s* \d+ [+]* [|] /x) { # Data record my %stats; @stats{@{$self->{fields}}} = map { s/^\s*// } split /\|/; foreach my $cleanup (@cleanups) { my ($key, $match, $replace, $global) = @$cleanup; $global ? ( $stats{$key} =~ s/$match/$replace/g ) : ( $stats{$key} =~ s/$match/$replace/ ) } # convert time from MM:SS to seconds $stats{$_} = $self->time_to_dec($stats{$_}) for qw(last_la +p best_lap); $stats{id} = $stats{car}; #Logger->log(Dumper(%stats)); push @{$session{positions}}, \%stats; } elsif (/^</) { # Header my @values = split(/\|/); my $abbrv = $values[5]; $session{flag} = $abbreviations{$abbrv} // $abbrv unless $abbrv eq ''; my $msg = $values[16]; $msg =~ s/^>//; $msg =~ s/^.* : //; $session{control_message} = $msg unless $msg =~ /^\S+ flag +/i; $session{event} = $values[0]; $session{event} =~ s/\<\!(.*)/$1/; } else { #print "garbage: $_\n"; } } Logger->log("series: |$session{series}| event: |$session{event}| f +lag: |$session{flag}| time: |$session{time}|"); return %session; }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'