#!/usr/bin/perl
use strict;
use warnings;
my @array = ( 1..20 );
my @array2 = ( 1000..1005 );
print "\@array : @array\n\@array2 : @array2\n";
my @rmArray = splice ( @array, 5, scalar(@array2), @array2 );
print "After spliece\n";
print "\@array : @array\n\@rmArray : @rmArray\n";
Result :
$ perl splice.pl
@array : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
@array2 : 1000 1001...
Friday, December 2, 2011
Perl - [ $perl -e ' Command Line ' ] - [ Shift / Unshift / Pop / Push ]
Note: Open shell and type the code "command line" below!Syntax : $ perl -e ' command line '1) Profile example
$ perl -e '@array = (1..5); print "Result : @array \n";'
Result : 1 2 3 4 5
2) Removes the first element of the array
$ perl -e '@array = (1..5); shift (@array);print "Result : @array \n";'
Result : 2 3 4 5
3) Remove the last element of the array
$...
Wednesday, November 30, 2011
Sunday, November 13, 2011
Perl - [ Seconds To Hours ]
#!/usr/bin/perluse strict;use warnings;my $seconds = shift or die "Entre the seconds parameter\n";my @parts = gmtime($seconds);printf ("day -%4d\t hours - %4d\tminute - %4d\tseconds - %4d\n",@parts[7,2,1,0]);
$perl secondsTohours.pl 89600day - 1 hours - 0 minute - 53 seconds - ...
Perl - [ Second TO Hours [Sub] ]
#!usr/bin/perl
use strict;
use warnings;
my $value = shift or die "Enter the second parameter\n";
&secondTOhours(\$value);
sub secondTOhours(){
my ($seconds)= @_;
my $hrs = int( $$seconds / (60*60) );
my $min = int( ($$seconds - $hrs*60*60) / (60) );
my $sec = int( $$seconds - ($hrs*60*60) - ($min*60) );
print("$hrs...
Thursday, November 3, 2011
Perl - [ Reference | Array Sub ]
#!/usr/bin/perl
use strict;
use warnings;
my @array = [1,2,3,['a','b',['c']]];
my $rA = \@array;
print"\n[0] = [1,2,3,['a','b',['c']]]";
print"\n[3] = ['a','b',['c']]";
print"\n[2] = ['c']";
print"\n[0] = c";
print "\nResp : $rA->[0][3][2][0]\n";
my @des = [ ['andre','21','PA'],
['ela','-','SP']];
my $rD = \@des;
print $rD->[0][0][0];
result
$...
Perl - [ Captura Regex ]
#!/usr/bin/perl
use strict;
use warnings;
my $capitura = 'From: gnat@perl.com To: camelo@oreilly.com Date: Mon 17 Jul 200 09:00:00 -100 Subject: Nada';
$capitura =~ /(From:(.*)To:(.*)\s{1}Date:(.*)\s{1}Subject:(.*))/;
print "$1\n$2\n$3\n$4\n$5";
result
$perl commandLine.pl
$1 # From: gnat@perl.com To: camelo@oreilly.com Date: Mon 17 Jul 200 09:00:00 -100 Subject: Nada
$2 # gnat@perl.com
$3...
Perl - [Character class | Change | Replacement | For ]
#!/usr/bin/perl
use strict;
use warnings;
my $name = ' texto gerado automaticamente pelo sistema lattes ';
my $name1;
($name1 = $name) =~ s/o/OoO/g;
print "$name\n$name1\n";
for ($name){
s/^\s+/+/;
s/\s+$/++/;
s/\s+/-/g;
}
print "$name\n";
my @names = ('comand',' ','line');
print "@names\n";
tr/ /./ for @names;
print "@names\n";
my...
Tuesday, November 1, 2011
Friday, October 28, 2011
Perl - [ Shift ]
#!/usr/bin/perl
use strict;
use warnings;
my %hash = ('1' => 'Perl','2' => 'Linux','3' => 'Bioinformatics');
my $key = shift or die "Key not found\n";
if($key){
print "$hash{$key}\n";
}
Result
$ perl blog.pl 1
Perl
$ perl blog.pl 2
Linux
$ perl blog.pl 3
Bioinformatics
$ perl blog.pl
Key not fo...
Perl - Pattern Matching [ Print`s ... ]
#!/usr/bin/perl
use strict;
use warnings;
my $text = "encrypted key\n";
if ($text =~ /key/){
print qq/$text new print !\n/;
}
if(lc ($text) =~ /key/){
print "$text";
}
$text = "/home /andre /work /tmp /bin";
if($text =~ m[/bin]){
print "Directory /tmp found!\n";
}
$text = "andre luiz\n";
$text =~ s(andre)<AnDrE>;
$text =~ s[l]/L/;
$text =~...
Wednesday, October 26, 2011
Perl - Pattern Matching [ regular expression ]
Metacharacter: Actually, they are very useful and have special meanings within the patterns./ | () [] {} ^ $ * +? .\: The backslash and a wildcard that has the 'power' to transform into something special character literale.g. \ b \ D \ t \ 3
Pattern
#!/usr/bin/perl
use...
Monday, October 24, 2011
Perl - (school media) [hash , array]
#file txt separado por tab
alunosnotasbimestral
ayes 8.5 6.5 7.0 10.0
andre 7.0 9.0 8.5 8.5
la 9.0 7.0 4.5 7.5
gui 4.5 8.0 8.0 6.0
lu 4.0 4.0 4.0 4.0
-----------------------------------------------------------------------------------------------------------------------------
#!usr/bin/perl
use strict;
use warnings;
my %nomes;
my $media = 0;
my $qnt = 4;
open(IN,'alunosnotasbimestral')...
Saturday, October 22, 2011
Mysql - [ Sub Query ] function (exists,)
mysql> select * from tabela3;
+--------+--------+-------+------------+
| nome | codigo | idade | data |
+--------+--------+-------+------------+
| gilmar | 1 | 24 | 2011-10-10 |
+--------+--------+-------+------------+
1 row in set (0.00 sec)
mysql> select * from tabela2;
+-----------+-------+--------+------------+
| nome1 ...
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...
Thursday, October 20, 2011
Perl - [ Hash / Sub / Sort / Keys ]
#!/usr/bin/perl
use strict;
use warnings;
my (%HoHoA);
@{$HoHoA{'1'}{'1'}} = (1..10);
@{$HoHoA{'1'}{'2'}} = (11..20);
@{$HoHoA{'1'}{'3'}} = (21..30);
@{$HoHoA{'1'}{'4'}} = (31..40);
&print_ed(\%HoHoA);
sub print_ed{
my ($rHoHoA) = @_;
foreach my $kA (keys %{$rHoHoA}){
foreach my $kB ( sort{$rHoHoA->{$kA}{$b}[1] <=> $rHoHoA->{$kA}{$a}[3]...
Tuesday, October 18, 2011
Perl - [ Functions / Reference ]
#!/usr/bin/perl
use strict;
use warnings;
&a();
sub a{
my @nome = ('ayres','andre');
print "Rotina a antes: " , join ("\t",@nome) , "\n";
&print_a(\@nome);
print "Rotina a depois: " , join ("\t",@nome) , "\n";
}
sub print_a{
my ($rA_teste) = @_;
...
Perl - TABLE [ REFERENCE ] \o/
ReferenceDefinitionSearch value Alternative
climb$Ref = \$climb$$Ref${$Ref}
matrix$Ref = \@matrix@$Ref@{$Ref}
element matrix$Ref = \@matrix@{$Ref}[0]$Ref->[0]
hash$Ref = \%Hash%$Ref%{$Ref}
element hash$Ref = \%Hash%{$Ref}{"Name"}$Ref->{"Name"}
Save ....
Perl - [ References /pointers variables ]
Anyone familiar with the C language (and other), you know whatpointers are and how programming can become proficient with its use. References are pointers to previously defined data types(whether it's scalars, arrays or hashes). Through references it is possible to obtain the contents of a scalar variable, an...
Friday, October 14, 2011
Perl - ( if ) [ testing if uninitialized variable! ]
#!/usr/bin/perl
use strict;
use warnings;
my $key ; not initialized
if($key != 0){ # line 7
print "1ok\n";
}
if($key != ''){ # line 10
print "2ok\n";
}
if($key ne 0){ # line 13
print "3ok\n";
}
if($key ne ''){ #line 16
print "4ok\n";
}
if($key){ # line 19
print "5ok\n";
}
resul
$ perl tmp.pl
Use of uninitialized...
Thursday, October 13, 2011
Perl Hash [SINTAXE]
high voltage =)
----------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;\
my $key = 1;
my $hash;
@{$hash->{$key}} = ("10","11");
$hash->{1}[2] = "sintaxe\n";
print join ("|",@{$hash->{1}});
Result
$ perl tmp.pl
10|11|sintaxe...
Friday, October 7, 2011
Perl - [ Expression ]
#!/usr/bin/perl
use strict;
use warnings;
my $var = 'LGMB-RP_06242011_HGWSI_1.fastq.sai.sam.bam.sort.bam';
if( $var =~ /^(.*)\.fastq/ ){
$var = $1;
}
print"$var\n";
$var = 'LGMB-RP_06242011_HGWSI_1.fastq.sai.sam.bam.sort.bam';
$var = "$1.sam" if( $var =~ /^(.*)\.sam/ );
print"$var\n";
$ perl t.pl
LGMB-RP_06242011_HGWSI_1
LGMB-RP_06242011_HGWSI_1.fastq.sai.sam...
Thursday, October 6, 2011
Perl -[ if , unless ]
#!/usr/bin/perl
use strict;
use warnings;
my $val = 1;
#first
print "first (if)\n";
if($val > 1){
print "if > 1\n";
}else{
print "else <= 1\n";
}
not functional
#second
print "second (if)\n";
$val = 2;
if($val < 1){
print "if < 1\n";
}unless($val > 1){
print "unless <...
Perl - A [ Switch ] statement
Necessary import library.
Initialize the variable and play ($val).
#!/usr/bin/perl
use strict;
use warnings;
use Switch;
my $val = 'a';
switch ($val) {
case 1 { print "number 1" }
case "a" { print "string a" }
case [1..10,42] { print "number in list" }
case /\w+/ { print "pattern" }
case qr/\w+/ { print "pattern" }
else { print "previous...
Wednesday, October 5, 2011
Perl - [Function] (Sort)
Number
#!usr/bin/perl
use strict;
use warnings;
my @blog = (1,7,6,34,2,46,7);
print "disorderly\n";
print join (" ",@blog);
@blog = sort @blog;
print "\norderly - the first number\n";
print join (" ",@blog);
print "\norderly - the complete number( descending order )\n";
@blog = sort {$b <=> $a} @blog;
print join (" ",@blog);
print...