I am trying to parse a text file with the following code:
sub parse { open(CLOG, "<$flatfile") || die ("Cannot open $flatfile for readin +g... $!\n"); foreach $tracknumber (<CLOG>) { $tracknumber =~ s/\<Num_0\>/0/g; $tracknumber =~ s/\<Num_1\>/1/g; $tracknumber =~ s/\<Num_2\>/2/g; $tracknumber =~ s/\<Num_3\>/3/g; $tracknumber =~ s/\<Num_4\>/4/g; $tracknumber =~ s/\<Num_5\>/5/g; $tracknumber =~ s/\<Num_6\>/6/g; $tracknumber =~ s/\<Num_7\>/7/g; $tracknumber =~ s/\<Num_8\>/8/g; $tracknumber =~ s/\<Num_9\>/9/g; $tracknumber =~ s/\<Num_\.\>/\./g; $tracknumber =~ s/\<Num_\-\>/\-/g; $tracknumber =~ s/\<Num_\/\>/\//g; $tracknumber =~ s/\<Tab\>/\t/g; $tracknumber =~ s/\<Tab//g; $tracknumber =~ s/\<Up\>//g; $tracknumber =~ s/\<Down\>//g; $tracknumber =~ s/\<Alt\>//g; $tracknumber =~ s/\<Ctrl\>//g; $tracknumber =~ s/\<PgDwn\>//g; $tracknumber =~ s/\<PgUp\>//g; $tracknumber =~ s/\xA0/ /g; $tracknumber =~ s/\xA1//g; $tracknumber =~ s/\xA2//g; $tracknumber =~ s/\xA4//g; $tracknumber =~ s/\x0D/\n/g; $tracknumber =~ s/\x0A/\n/g; $tracknumber =~ s/\<Num_//g; $tracknumber =~ s/\<Num//g; $tracknumber =~ s/\<Nu//g; $tracknumber =~ s/\<Numpad_3\>/\n/g; $tracknumber =~ s/pad_3\>/\n/g; open(OUTPUT, "+>>$output") || die ("Cannot open output file$!\ +n"); print OUTPUT "$tracknumber"; close OUTPUT; } close CLOG; }
As you can see, I am doing quite a few search and replace functions, but the problem I am having is this: the text file from which I'm reading also contains statements such as <Left>, <Right>, and <Del> (it is the output from a keylogger), and I need to reflect the cursor movement that these keys cause in the final output file (I am parsing the output file because it the text is quite unreadable straight out of the logger.) Also, does anyone have an idea about how I might be able to parse the whole file in one big chunk instead of line-by-line (as "foreach" does)? The line-by-line business really messes up the final parsed output. Thanks guys/gals!

In reply to Parsing Issue by alkaloid

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.