in reply to duplicate lines in array
There are of course many other ways to do this. Here is one.
Output:
#!/usr/local/bin/perl5.6.0 -w use strict; # array of records my @contact_type = ( 'N(8) -- H(15) .. O(9)', 'N(8) -- H(15) .. N(8)', 'N(8) -- H(16) .. O(9)', ); my %count_hash; # used to store matching lines for ( map { [ /(H\(\d+\))/, $_ ] } @contact_type ) { push( @{$count_hash{$_->[0]}}, $_->[1] ); } for ( keys %count_hash ) { if ( scalar( @{$count_hash{$_}} ) > 1 ) { print qq{$_\n} for ( @{$count_hash{$_}} ); } }
Output:
Wonko:!./test.pl N(8) -- H(15) .. O(9) N(8) -- H(15) .. N(8)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: duplicate lines in array
by Roger (Parson) on Jan 23, 2004 at 14:06 UTC | |
by Skeeve (Parson) on Jan 23, 2004 at 14:30 UTC | |
by Roger (Parson) on Jan 23, 2004 at 14:43 UTC | |
by Fletch (Bishop) on Jan 23, 2004 at 15:01 UTC | |
by Skeeve (Parson) on Jan 23, 2004 at 15:15 UTC | |
Re: Re: duplicate lines in array
by mcogan1966 (Monk) on Jan 23, 2004 at 13:24 UTC | |
Re: Re: duplicate lines in array
by harry34 (Sexton) on Jan 27, 2004 at 10:44 UTC | |
by pelagic (Priest) on Jan 27, 2004 at 11:50 UTC | |
by harry34 (Sexton) on Jan 27, 2004 at 12:39 UTC | |
by pelagic (Priest) on Jan 27, 2004 at 13:00 UTC | |
by harry34 (Sexton) on Jan 27, 2004 at 13:45 UTC | |
|
In Section
Seekers of Perl Wisdom