Friday, October 21, 2011

Perl [ hash - Single sample ]

Assuming you have a sample with a column that presenter replications.
you to remove repetitions and maintain a single sample!

-----------------------------------------------------------------------------------------------------------

#!/usr/bin/perl
use strict;
use warnings;


various boot
=cut   # commeted 
my %hash;
$hash{1}='hard';
$hash{1}='soft';
$hash{1}='hard';
$hash{1}='soft';
$hash{2}='perl';
$hash{2}='linux';
$hash{2}='perl';
$hash{2}='linux';
=cut



my %hash=('hard'=>'1',
        'soft'=>'2',
        'hard'=>'3',
        'soft'=>'4',
        'perl'=>'5',
        'linux'=>'6',
        'perl'=>'7',
        'linux'=>'8');


my %hashTmp;
foreach my $key (keys %hash){
    if(exists $hashTmp{$key}){
        next;
    }else{
        $hashTmp{$key} = $hash{$key};
        print "single sample - $key\n";
    }
}


$perl command_line.pl


single sample - perl
single sample - soft
single sample - linux
single sample - hard

Related Posts:

  • Rman / ORACLE $rman target / nocatalog Recovery Manager: Release 10.2.0.5.0 - Production on Tue Dec 11 16:05:05 2012 Copyright (c) 1982, 2007, Oracle.  All … Read More
  • Oracle - CONNECT_PERL_CMD use strict; use warnings; my $connect_string = 'username/password@server'; # connection to the DB my $file = 'test.sql'; # location of SQL file. Th… Read More
  • Perl with SQLServer -> =) use DBI; my $dsn = 'DBI:ODBC:Driver={SQL Server}'; my $host = 'WINSRV'; my $database = 'Relatorios'; my $user = 'sa'; my $auth = 'm1f1g1f4$'; my $… Read More
  • Oracle - Listener Examples: -- SQL> ALTER SYSTEM SET service_names='svr_oracle_prd.com.br' SCOPE=MEMORY SID='orcl_prd'; -- SQL> show parameter service_na… Read More
  • Bytecode [ Perlcc is dead on RedHat 6.* -> PP new Solution ] #Commands CD_IN='cd' CD_OUT='cd ..' TAR='tar -xvzf' PERL_MAKEFILE='perl Makefile.PL' MAKE='make' MAKE_INSTALL='make install' CHMOD='chmod +x Makefile… Read More

0 comentários:

Post a Comment