I'm trying to parse a log file and I'm pretty sure it is really easy, I'm just mixing some commands and getting weird results. Please see below.

Here's my script
#!/usr/bin/perl use strict; my %record = (); my ($title, $row); while (<>) { if (m/^\scustomer/i ... /rows\)/) { chomp; next if (/^\s+$/); next if (/^TEST/); next if (/---/); next if (/row/); if ($_ =~ m/\s(\D+)/i) { $title = $1; } if ($_ =~ m/\s+(\d+)/i) { $row = $1; } $record{$title} = $row if ( $title ne " "); } } map { print "$_ -> $record{$_}\n" } %record;


Sample Data:
TEST HEADER CUSTOMERPHONE ----------- 1300 (1 row) TEST HEADER CUSTOMERORDER ----------- 0 (1 row) TEST HEADER CUSTOMERCARE ----------- 530 (1 row)


Output that I am getting:
CUSTOMERORDER -> 1300 1300 -> -> 530 530 -> CUSTOMERPHONE -> -> CUSTOMERCARE -> 0 0 ->


Output that I want:
CUSTOMERPHONE -> 1300 CUSTOMERORDER -> 0 CUSTOMERCARE -> 530

In reply to Parsing a Simple Log File by bichonfrise74

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.