in reply to finding duplicate data

use a hash to count the number of each string occurance.
#!/usr/bin/perl while (<DATA>){ chomp; $h{$_}++; } for ( sort grep { $h{$_} != 1 } keys %h ) { print "$_\n"; } __DATA__ A(01) B(02) C(03) A(01) D(04) E(05)
Boris

Replies are listed 'Best First'.
Re: Re: finding duplicate data
by harry34 (Sexton) on Jan 21, 2004 at 11:23 UTC
    That works great !.
    What is the second part of the code doing ?
    i.e. how is it working ?
      Which part has you puzzled? grep? for () implicitly setting $_? (If the former, you should be able to run "perldoc -f grep" to get a description of what grep does. If for some reason you have a broken perl that doesn't include perldoc, try here.)
        What if I have an array called (@hydrogen_split).
        Could I not write your code like this ?

        foreach $i(0..@hydrogen_split){ chomp; $hydrogen_split{$key}++; } for ( sort grep { $hydrogen_split{$key} !=1 } keys %hydrogen_split){ print "$key\n"; }