Tom,

I did make some changes but that actually is still causing me to
output each line while looping through the file instead of only adding
unique key value pairs to the hash.  I can only guess I am overriding
the hash each time it loops?  Also don't understand the line break I
am getting between the number and is unique.


So the input is:  (I did mean to type a | when I wrote this post but
just didn't)
products.out
cellphone|52
cola|23
monitors|32
cellphone|23
mugs|1000
cellphone|52

Code:
open(FILE, "<products.out") or die "1. Can't open $FILE for reading:
$!. Stopped";
my(%hash);
while(<FILE>) {
    ($product, $qty) = split /\|/, $_;
    if (exists $hash{$product}){
       #do nothing
    }
    else {
       $hash{$product} = $qty;
       print "The $product is unique\n";
    }
}

Output:

The 52
 is unique
The 23
 is unique
The 32
 is unique
The 23
 is unique
The 1000
 is unique
The 52
 is unique


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to