Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: select only duplicate entries

by borisz (Canon)
on Aug 24, 2006 at 08:55 UTC ( #569321=note: print w/replies, xml ) Need Help??

in reply to select only duplicate entries

my %h; while ( defined ( $_ = <DATA> )){ chomp; my ( $k, $v) = split ' '; push @{$h{$k}}, $v; } open my $fh1, '>', '/tmp/1.txt' or die; open my $fh2, '>', '/tmp/2.txt' or die; for my $k ( sort keys %h ) { my $c = @{$h{$k}}; for ( @{$h{$k}}){ $c > 1 ? print $fh2 "$k\t$_\n" : print $fh1 "$k\t$_\n"; }} __DATA__ protein1 stomach protein2 head protein3 muscle protein3 heart protein3 brain protein4 leg protein5 toes protein5 mouth protein6 ear

Replies are listed 'Best First'.
Re^2: select only duplicate entries
by ikegami (Pope) on Aug 24, 2006 at 15:08 UTC

    while ( defined ( $_ = <DATA> )){
    is equivalent to
    while ( <DATA> ){

    $c > 1 ? print $fh2 "$k\t$_\n" : print $fh1 "$k\t$_\n";
    is equivalent to
    print { $c == 1 ? $fh1 : $fh2 } "$k\t$_\n";
    or do
    my $fh = $c == 1 ? $fh1 : $fh2;
    outside the loop and print to $fh.

      Thanks, I know. I try to write it simple for the newbies.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://569321]
virtualsue upgrades modules
[erix]: aka *falling forward*
[Corion]: virtualsue: That sounds weird... I don't think we do fancy stuff like chunked encoding or something. Maybe your DNS is unlucky and gets the low machine.
[Corion]: But at least headers should be available

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-12-13 12:00 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (360 votes). Check out past polls.