A few more pointers on your code.

You don't need to check for existence when incrementing the value of a hash key:

if(exists $userhash{$username}) { $userhash{$username}++; } else{ $userhash{$username}=1 ; }

can be written in a single line:

$userhash{$username}++;

It's more readable and maintainable to use Quantifiers (see perlre) in a regular expression than using a string of repeated characters or character classes:

So, [0-9][0-9][0-9][0-9] would have been better if written like [0-9]{4} (in that specific instance, \d{4} would have been even better).

When checking for a value that's being incremented or decremented, it's good defensive programming to check not just the terminating value but also all values beyond that. This will often avoid infinite loops.

So, $bigcounter == 100000 would be better as $bigcounter >= 100000 and similarly for $done != 0.

When using open, it's good practice to separate the mode (e.g. '<' for reading, '>>' for appending, etc.) from the file name. It's also good practice to use a lexically scoped filehandle (e.g. my variable) rather than a global. Also, when using or die ... the parentheses are not required - they are if you use || die ....

Putting that all together

open( INPUTDATAFILE, "< $inputfile" ) or die ...

would become

open my $inputdatafile, '<', $inputfile or die ...

In closing, I will compliment you on your code in general (neatly laid out, meaningful variable names and so on) - don't stop doing that. :-)

-- Ken


In reply to Re: Script Help! by kcott
in thread Script Help! by blackice69

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.