Here's some working code to show the outline of a different approach. I've substituted in some self-contained data for demo purposes. Hope this helps.
#!/usr/bin/perl -w use strict; sub parse { my $flatfile = shift; my %replace = ('<Tab>' => "\t", '<Numpad_3>' => "\n", 'pad_3' => "\n", 'etc' => "etc", ); my @delete = ('<Tab>', '<Up>', '<Down>', '<PgUp>', '<Num_', '<Num', '<Nu', 'etc', 'etc', ); #open(CLOG, "<$flatfile") # || die ("Cannot open $flatfile for reading... $!\n"); #foreach $tracknumber (<CLOG>) { foreach my $tracknumber (<DATA>) { for my $chr ('0'..'9', '-', '/', '.') { $tracknumber =~ s/<Num_($chr)>/$chr/g; } for (keys %replace) { $tracknumber =~ s/$_/$replace{$_}/g; } for (@delete) { $tracknumber =~ s/$_//g; } #open(OUTPUT, "+>>$output") # || die ("Cannot open output file$!\n"); #print OUTPUT "$tracknumber"; #close OUTPUT; print "$tracknumber"; } #close CLOG; } parse('somefile'); __DATA__ Since I have no idea what keylogger data looks <Tab>like,<Up> I'll just <PgUp> have to fudge <Tab>up<Down> something <Num_4> a test<Num_.>
Regarding your line-by-line issue. I suspect something else is the cause of your messed-up output. (Specifics, please) But if the file is not too big, you can suck the whole thing up into a single scaler and then do the three s/// alterations on the whole thing at once.

Update: After sleeping on it, I repent of suggesting the use of a hash to store the %replace data. It works in this case but it's a risky pattern. The order that keys are returned from a hash is not guaranteed. So consider the @delete data above and imagine if 'Num_', 'Num', and 'Nu' were replace items. If the data at hand were 'blah blah Num_ blah', it would make a difference if 'Nu' were evaluated before the other two. So we need to store these Replace items in an array to assure they will be evaluated in the specified order. It could be an array of hashes but there's no need for that, an array of arrays will do nicely and is more efficient. (untested snippets follow)

my @replace = (['<Tab>', "\t"], ['<Numpad_3>', "\n"], ['pad_3', "\n"], ['etc', "etc"]); # ... later in loop foreach my $aref (@replace) { $tracknumber =~ s/$aref->[0]/$aref->[1]/g; }

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall


In reply to Re: Parsing Issue by dvergin
in thread 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.