in reply to Re^2: Perl Hash Files
in thread Perl Hash Files

Detecting duplicates are what Tiggers and hashes do best:
while (<LOG>) { # Assume name of program is in $_ chomp; $hash{$_}++; }
The hash key will be created and the value set to undef (zero), then incremented on the first time around. Subsequent occurances of the same key will increment the value.

By the way, a small thing, but be careful when you use a leading zero on a numeric - it converts it to octal.

Replies are listed 'Best First'.
Re^4: Perl Hash Files
by blundell (Novice) on Dec 11, 2006 at 19:59 UTC
    thanks i have to use leading zero's because my text files are named 01 02 03 04, have to look for a way, can't i tell it not to change to octal? Do you mean it changed the hask key to octal?
      Do you mean it changed the hask key to octal?

      No. Hash keys and filenames are strings, not numbers, so the leading zero does nothing in those cases and has no impact on your program. (Quite aside from that, you also have only one digit after the zero, so these numbers would be the same in octal as in decimal, except for 08 and 09, which aren't even valid in octal and would therefore still be interpreted as decimal, so there's another reason it has no impact.) He was just making you aware for future reference that if you have something like '024' and then treat it like a number (e.g., by adding another number to it), the results may not be quite what you might expect. That's probably why he called it a "small thing", because it doesn't have any impact on the operation of your current program.


      Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.