On Thu, Sep 16, 2010 at 11:27, Jordi Durban <[email protected]> wrote:
> Hi all!
> I would like to ask you something. I have a file as follows:
> File A File B
> uid = 1 uid = 4
> uid = 2 uid = 3
> uid = 3 uid = 2
> uid = 4 uid = 1
>
> I'm trying to make a perl script to get me only those lines whose numbers
> are the same regardless in the column they are. That is, in the example, the
> second and third I want to appear only once.
> thank you
>
> --
> Jordi
>
Whenever you think the word unique, you should think: "hash!". Perl 5
has very nice hashes. A simple example similar you your problem is
#!/usr/bin/perl
use strict;
use warnings;
my %seen;
while (my $line = <>) {
chomp $line;
if ($seen{$line}++) {
print "I have seen '$line' $seen{$line} times.\n";
} else {
print "I have never seen '$line' before.\n";
}
}
If you type the same line twice it tells you it has seen the line before.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/