There is not really much you can idiomize, if you show all the code you want to change. But you can take inspiration from the following (untested):
use constant EVENT => 0; use constant ABBRV => 5; use constant MSG => 16; my %abbrevs = (G => 'Green', Y => 'Yellow', R => 'Red', C => 'Checkered', U => 'Unflagged', ); my %subs = (position => [qr/\+/, ''], # sometimes there is a " ++" driver => [qr/ *\(R\)$/, ''], # I don't care if rookie best_speed => [qr/\+/, ''], # sometimes there is a " ++" at end status => [qr/In Pit/i, 'Pit', qr/Active/, 'Run', qr/Pace_Laps/, 'Pace'], ); sub get_state { my ($self, $contents) = @_; $contents =~ s/\r//g; my %session; ## That's enough foreach (split /\n/, $contents) { if (/^ *\d+\+*\|/) { # Data record my @values = split(/\|/); s/^\ *// foreach @values ; my %stats; @stats{ @{ $self->{fields} } } = @values; # do some clean up / bring to common values if ($stats{status} eq '') { # not all the series track run, pi +t, etc $stats{status} = 'Run' } for my $stat (keys %subs) { my @subst = @{ $subs{$stat} }; while (my ($match, $replace) = splice @subst, 0, 2) { $stats{$stat} =~ s/$match/$replace/g; } } # convert time from MM:SS to seconds $stats{$_} = $self->time_to_dec($stats{$_}) for qw/last_lap best_lap/; $stats{id} = $stats{car}; #Logger->log(Dumper(%stats)); push @{ $session{positions} }, \%stats; } elsif (/^</) { # Header my @values = split(/\|/); my $abbrv = $values[ABBRV]; my $flag = exists $abbrevs{$abbrv} ? $abbrevs{$abbrv} : $a +bbrv; if ($abbrv ne '') { $session{flag} = $flag }; my $msg = $values[MSG]; $msg =~ s/^>//; $msg =~ s/^.* : //; $session{control_message} = $msg unless $msg =~ /^\S+ flag/i; $session{event} = $values[EVENT]; $session{event} =~ s/\<\!(.*)/$1/; } else { #print "garbage: $_\n"; } } ## One more space at the end Logger->log(join '| ', map "$_: |$session{$_}", qw/series event flag time/); return %session; }

In reply to Re: Idiomize This - Cleanup/Transform by choroba
in thread Idiomize This - Cleanup/Transform by johnr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.