Rob Dixon wrote: > Madhu Reddy wrote: > > Hi, > > I have following script, basically this will > > ding the duplicate rows in a file... > > > > I am getting following warnings > > Use of uninitialized value at Audit_WTN.pl line 133, > > <FH_IN_FILE> chunk 18. > > Use of uninitialized value at Audit_WTN.pl line 133, > > <FH_IN_FILE> chunk 19. > > > > how to avoid warning at following location.... > > 133 if ( $ret >= 1 ) { > > > > > > -------------------------------- > > # return 1, if record is duplicate > > #returns 0, if record is not duplicate > > sub find_duplicates () > > { > > 128 # get the key frim row > > 129 $key = substr($_,8,18); > > 130 $ret = $keys{$key}; > > > > 132 #Record is Duplicate > > 133 if ( $ret >= 1 ) { > > 133 $keys{$key}++; > > 134 return 1; > > } else { > > $keys{$key}++; > > return 0; #not a duplicate > > } > > } > > Simply > > sub find_duplicates () { $keys{substr($_, 8, 18)}++ } > > which will return the number of previous occurrences > of this key.
Actually, to be a little less opaque, there are a few situations where Perl will treat an undefined value as zero or the empty string depending on context. One of these is as the object of the increment operator, so the block: do { my $empty; $empty ++; }; will return zero and leave $empty with the value 1 (before it throws it away!) All I've done apart from that is to simplify your own code. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]