configfile.ini
--------------------------------------------------------------------------------------------------------------
[db]
user = Command Line
pass = 123
--------------------------------------------------------------------------------------------------------------
blog.pl
--------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Config::IniFiles;
my $config = Config::IniFiles->new (-file => "configfile.ini");
my $usr = $config->val('db','user');
my $pass = $config->val('db','pass');
print "Name : $usr\tPassword : $pass\n";
--------------------------------------------------------------------------------------------------------------
Result:
perl blog.pl
Name : Command Line Password : 123
[ORACLE] [SQLSERVER] [POSTGRES] [MYSQL] [DBA] [UNIX] [LINUX] [WINDOWS] [FREEBSD] [REDHAT] [SQL] [PERL] [SH] [BAT] [SCRIPT]
Friday, June 22, 2012
Tuesday, June 12, 2012
Perl - [ Working with parameter ]
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
## setup my defaults
my $name ;
my $age ;
my $help = 0;
GetOptions(
'n|name=s' => \$name,
'a|age=i' => \$age,
'help!' => \$help,
) or die "Incorrect usage!\n";
if( $help ) {
print "perl script.pl -n blog -a 2\n";
} else {
print "My name is $name.\n";
print "I am $age years old.\n";
}
-----------------------------------------------------------------------------------------------------------
:~> perl script.pl -n andre -a 22
My name is andre.
I am 22 years old.
use strict;
use warnings;
use Getopt::Long;
## setup my defaults
my $name ;
my $age ;
my $help = 0;
GetOptions(
'n|name=s' => \$name,
'a|age=i' => \$age,
'help!' => \$help,
) or die "Incorrect usage!\n";
if( $help ) {
print "perl script.pl -n blog -a 2\n";
} else {
print "My name is $name.\n";
print "I am $age years old.\n";
}
-----------------------------------------------------------------------------------------------------------
:~> perl script.pl -n andre -a 22
My name is andre.
I am 22 years old.
PERL - Validate Palindromo
validate.pl
--------------------------------------------------------------------------------------------------------------
#!/bin/bin/perl
use strict;
use warnings;
my $palavra = shift or die $!;
my @array = split(//,$palavra);
my ($max,$valida) = ($#array,0);
for(my $i = 0; $i <= $#array/2; $i++ ){
if($array[$i] eq $array[$max]){
$valida ++;
}
$max --;
}
if($valida >= ($#array/2) ){
print "@array:\tPalindromo YES\n";
}else{
print "@array:\tPalindromo NO\n";
}
--------------------------------------------------------------------------------------------------------------
:~> perl validate.pl arara
a r a r a: Palindromo YES
:~> perl validate.pl arar
a r a r: Palindromo NO
:~> perl validate.pl tenet
t e n e t: Palindromo YES
:~> perl validate.pl tene
t e n e: Palindromo NO
--------------------------------------------------------------------------------------------------------------
#!/bin/bin/perl
use strict;
use warnings;
my $palavra = shift or die $!;
my @array = split(//,$palavra);
my ($max,$valida) = ($#array,0);
for(my $i = 0; $i <= $#array/2; $i++ ){
if($array[$i] eq $array[$max]){
$valida ++;
}
$max --;
}
if($valida >= ($#array/2) ){
print "@array:\tPalindromo YES\n";
}else{
print "@array:\tPalindromo NO\n";
}
--------------------------------------------------------------------------------------------------------------
:~> perl validate.pl arara
a r a r a: Palindromo YES
:~> perl validate.pl arar
a r a r: Palindromo NO
:~> perl validate.pl tenet
t e n e t: Palindromo YES
:~> perl validate.pl tene
t e n e: Palindromo NO
Perl - [ SCRIPT TO BACKUP ]
backup.pl
------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $path = shift or die $!;
my $dir_out = 'backup_Perl';
`mkdir $dir_out` unless (-e "$dir_out");
print `find $path -name "*.pl" > tmp_path_backup`;
open (IN,"tmp_path_backup") or die $!;
while(<IN>){
chomp;
print `cp $_ $dir_out/`;
}
close(IN);
print `rm tmp_path_backup`;
------------------------------------------------------------------------------------------------------------
$perl backup.pl projects/
-bash-4.0$ ls
Área de trabalho backup_Perl backup.pl Documentos Downloads igv Imagens Modelos Música projects Público Vídeos
-bash-4.0$ ls backup_Perl/
annotCDS.pl convert_1.pl createTable_new.pl format_refGeneCDS.pl getInterestGene.pl insert_dbSNP.pl qualitySam.pl samStatus.pl tmp.pl
annotSomatic.pl convert_2.pl createTable.pl frequency.pl grepCount.pl insertFall.pl rand_change2.pl samTOcsfasta.pl troca.pl
bamTopileup.pl countAlleleDefth.pl create_Triplet.pl function_IUPAC.pl grepTable4.pl merge_col_HmmMergeDBsnp.pl rand_change.pl select_dbSNP.pl tryTochange.pl
computerFile.pl countTabla4_1.pl dif.pl geneArray.pl gretable4.3.pl merge.pl rank_BIOSCOPE_conv.pl separa.pl
computerIntro.pl createTable_CDSannot.pl fasta2stockholm_userHMMSERACH.pl getFTP.pl HmmMergeDBsnp.pl pileupCVR.pl recorverName.pl sort_Merge.pl
computer.pl createTableIndel.pl formaTOdb.pl getInfo.pl hmm_parser.pl pipeline.pl recover.pl TESTEannotSomatic.pl
------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $path = shift or die $!;
my $dir_out = 'backup_Perl';
`mkdir $dir_out` unless (-e "$dir_out");
print `find $path -name "*.pl" > tmp_path_backup`;
open (IN,"tmp_path_backup") or die $!;
while(<IN>){
chomp;
print `cp $_ $dir_out/`;
}
close(IN);
print `rm tmp_path_backup`;
------------------------------------------------------------------------------------------------------------
$perl backup.pl projects/
-bash-4.0$ ls
Área de trabalho backup_Perl backup.pl Documentos Downloads igv Imagens Modelos Música projects Público Vídeos
-bash-4.0$ ls backup_Perl/
annotCDS.pl convert_1.pl createTable_new.pl format_refGeneCDS.pl getInterestGene.pl insert_dbSNP.pl qualitySam.pl samStatus.pl tmp.pl
annotSomatic.pl convert_2.pl createTable.pl frequency.pl grepCount.pl insertFall.pl rand_change2.pl samTOcsfasta.pl troca.pl
bamTopileup.pl countAlleleDefth.pl create_Triplet.pl function_IUPAC.pl grepTable4.pl merge_col_HmmMergeDBsnp.pl rand_change.pl select_dbSNP.pl tryTochange.pl
computerFile.pl countTabla4_1.pl dif.pl geneArray.pl gretable4.3.pl merge.pl rank_BIOSCOPE_conv.pl separa.pl
computerIntro.pl createTable_CDSannot.pl fasta2stockholm_userHMMSERACH.pl getFTP.pl HmmMergeDBsnp.pl pileupCVR.pl recorverName.pl sort_Merge.pl
computer.pl createTableIndel.pl formaTOdb.pl getInfo.pl hmm_parser.pl pipeline.pl recover.pl TESTEannotSomatic.pl
Sunday, June 10, 2012
LiNuX - To modify [ Hour / date ]
$ sudo su
# date 061016592012
Sun Jun 10 16:59:00 PDT 2012
Desc : month day hour minute year
# date 061016592012
Sun Jun 10 16:59:00 PDT 2012
Friday, June 8, 2012
Mysql && Perl / [ toGenerate_TIME | Show ]
toGenerate_TIME.pl
-------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $myInterval = shift or die print "Usage : ./toGenerate_TIME.pl 30\n $!";
my $Time_start = 0;
my $Time_stop = 23;
my $interval = 0;
print "create table horas(id int(10) primary key auto_increment, horario time);\n";
while($Time_start <= $Time_stop){
if($interval){
if( $Time_start < 10){
print "INSERT INTO horas (horario) VALUES ('0$Time_start:$interval:00');\n";
}else{
print "INSERT INTO horas (horario) VALUES ('$Time_start:$interval:00');\n";
}
}else{
if($Time_start < 10){
print "INSERT INTO horas (horario) VALUES ('0$Time_start:00:00');\n";
}else{
print "INSERT INTO horas (horario) VALUES ('$Time_start:00:00');\n";
}
}
$interval += $myInterval;
if($interval >= 60) {
$Time_start++;
$interval = 0;
}
}
-------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $myInterval = shift or die print "Usage : ./toGenerate_TIME.pl 30\n $!";
my $Time_start = 0;
my $Time_stop = 23;
my $interval = 0;
print "create table horas(id int(10) primary key auto_increment, horario time);\n";
while($Time_start <= $Time_stop){
if($interval){
if( $Time_start < 10){
print "INSERT INTO horas (horario) VALUES ('0$Time_start:$interval:00');\n";
}else{
print "INSERT INTO horas (horario) VALUES ('$Time_start:$interval:00');\n";
}
}else{
if($Time_start < 10){
print "INSERT INTO horas (horario) VALUES ('0$Time_start:00:00');\n";
}else{
print "INSERT INTO horas (horario) VALUES ('$Time_start:00:00');\n";
}
}
$interval += $myInterval;
if($interval >= 60) {
$Time_start++;
$interval = 0;
}
}
-------------------------------------------------------------------------------------------------------------------------
$ perl toGenerate_TIME.pl 30
create table horas(id int(10) primary key auto_increment, horario time);
INSERT INTO horas (horario) VALUES ('00:00:00');
INSERT INTO horas (horario) VALUES ('00:30:00');
INSERT INTO horas (horario) VALUES ('01:00:00');
INSERT INTO horas (horario) VALUES ('01:30:00');
INSERT INTO horas (horario) VALUES ('02:00:00');
INSERT INTO horas (horario) VALUES ('02:30:00');
INSERT INTO horas (horario) VALUES ('03:00:00');
INSERT INTO horas (horario) VALUES ('03:30:00');
INSERT INTO horas (horario) VALUES ('04:00:00');
INSERT INTO horas (horario) VALUES ('04:30:00');
INSERT INTO horas (horario) VALUES ('05:00:00');
INSERT INTO horas (horario) VALUES ('05:30:00');
INSERT INTO horas (horario) VALUES ('06:00:00');
INSERT INTO horas (horario) VALUES ('06:30:00');
INSERT INTO horas (horario) VALUES ('07:00:00');
INSERT INTO horas (horario) VALUES ('07:30:00');
INSERT INTO horas (horario) VALUES ('08:00:00');
INSERT INTO horas (horario) VALUES ('08:30:00');
INSERT INTO horas (horario) VALUES ('09:00:00');
INSERT INTO horas (horario) VALUES ('09:30:00');
INSERT INTO horas (horario) VALUES ('10:00:00');
INSERT INTO horas (horario) VALUES ('10:30:00');
INSERT INTO horas (horario) VALUES ('11:00:00');
INSERT INTO horas (horario) VALUES ('11:30:00');
INSERT INTO horas (horario) VALUES ('12:00:00');
INSERT INTO horas (horario) VALUES ('12:30:00');
INSERT INTO horas (horario) VALUES ('13:00:00');
INSERT INTO horas (horario) VALUES ('13:30:00');
INSERT INTO horas (horario) VALUES ('14:00:00');
INSERT INTO horas (horario) VALUES ('14:30:00');
INSERT INTO horas (horario) VALUES ('15:00:00');
INSERT INTO horas (horario) VALUES ('15:30:00');
INSERT INTO horas (horario) VALUES ('16:00:00');
INSERT INTO horas (horario) VALUES ('16:30:00');
INSERT INTO horas (horario) VALUES ('17:00:00');
INSERT INTO horas (horario) VALUES ('17:30:00');
INSERT INTO horas (horario) VALUES ('18:00:00');
INSERT INTO horas (horario) VALUES ('18:30:00');
INSERT INTO horas (horario) VALUES ('19:00:00');
INSERT INTO horas (horario) VALUES ('19:30:00');
INSERT INTO horas (horario) VALUES ('20:00:00');
INSERT INTO horas (horario) VALUES ('20:30:00');
INSERT INTO horas (horario) VALUES ('21:00:00');
INSERT INTO horas (horario) VALUES ('21:30:00');
INSERT INTO horas (horario) VALUES ('22:00:00');
INSERT INTO horas (horario) VALUES ('22:30:00');
INSERT INTO horas (horario) VALUES ('23:00:00');
INSERT INTO horas (horario) VALUES ('23:30:00');
Mysql [ if / else | DATA / TIME ]
Sintaxe : IF(<condition>, <value if true>, <value if false>)
mysql> create table reserva(id int(10) primary key auto_increment, tempo time, data date);
Query OK, 0 rows affected (0.08 sec)
mysql> desc reserva;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| tempo | time | YES | | NULL | |
| data | date | YES | | NULL | |
+-------+---------+------+-----+---------+----------------+
3 rows in set (0.04 sec)
mysql> insert into reserva (tempo,data) values (CURTIME(),CURDATE());
Query OK, 1 row affected (0.00 sec)
mysql> insert into reserva (tempo,data) values ('10:33:40','2010-06-10');
Query OK, 1 row affected (0.39 sec)
mysql> insert into reserva (tempo,data) values ('05:43:40','2000-03-10');
Query OK, 1 row affected (0.00 sec)
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 00:11:42 |
+-----------+
1 row in set (0.03 sec)
mysql> select * from reserva where id = 1 and if(tempo > curtime() , 1 , 0 );
+----+----------+------------+
| id | tempo | data |
+----+----------+------------+
| 1 | 17:33:40 | 2012-06-08 |
+----+----------+------------+
1 row in set (0.00 sec)
mysql> select * from reserva where id = 1 and if(tempo > curtime() , 0 , 1 );
Empty set (0.00 sec)
mysql> select CURDATE();
+------------+
| CURDATE() |
+------------+
| 2012-06-09 |
+------------+
1 row in set (0.00 sec)
mysql> select * from reserva where id = 1 and if(data < curdate() , 1 , 0 );
+----+----------+------------+
| id | tempo | data |
+----+----------+------------+
| 1 | 17:33:40 | 2012-06-08 |
+----+----------+------------+
1 row in set (0.00 sec)
mysql> select * from reserva where id = 1 and if(data < curdate() , 0 , 1 );
Empty set (0.00 sec)
mysql> select * from reserva where id = 1 and if(data > curdate() , 1 , 0 );
Empty set (0.00 sec)
mysql> select * from reserva where id = 1 and if(data > curdate() , 0 , 1 );
+----+----------+------------+
| id | tempo | data |
+----+----------+------------+
| 1 | 17:33:40 | 2012-06-08 |
+----+----------+------------+
1 row in set (0.00 sec)
Mysql [Time/Data] / Select|Insert
mysql> create table reserva(id int(10) primary key auto_increment, tempo time, data date);
Query OK, 0 rows affected (0.08 sec)
mysql> desc reserva;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| tempo | time | YES | | NULL | |
| data | date | YES | | NULL | |
+-------+---------+------+-----+---------+----------------+
3 rows in set (0.04 sec)
mysql> insert into reserva (tempo,data) values (CURTIME(),CURDATE());
Query OK, 1 row affected (0.00 sec)
mysql> select * from reserva;
+----+----------+------------+
| id | tempo | data |
+----+----------+------------+
| 1 | 17:33:40 | 2012-06-08 |
+----+----------+------------+
1 row in set (0.00 sec)
mysql> select * from reserva where tempo < CURDATE();
Empty set (0.00 sec)
mysql> select * from reserva where tempo > CURDATE();
+----+----------+------------+
| id | tempo | data |
+----+----------+------------+
| 1 | 17:33:40 | 2012-06-08 |
+----+----------+------------+
1 row in set (0.00 sec)
mysql> select * from reserva where data = CURDATE();
+----+----------+------------+
| id | tempo | data |
+----+----------+------------+
| 1 | 17:33:40 | 2012-06-08 |
+----+----------+------------+
1 row in set (0.00 sec)
mysql> select * from reserva where data > CURDATE();
Empty set (0.00 sec)
mysql> select * from reserva where data < CURDATE();
Empty set (0.00 sec)
mysql> insert into reserva (tempo,data) values ('10:33:40','2010-06-10');
Query OK, 1 row affected (0.39 sec)
mysql> insert into reserva (tempo,data) values ('05:43:40','2000-03-10');
Query OK, 1 row affected (0.00 sec)
Thursday, June 7, 2012
Mysql [ Date ] Insert/Select
mysql> create table usr( id int(10) primary key auto_increment, nome longtext, data date);
Query OK, 0 rows affected (0.10 sec)
mysql> insert into usr (nome,data) values('andre','1990-04-07');
Query OK, 1 row affected (0.00 sec)
mysql> insert into usr (nome,data) values('marcelo','1994-03-31');
Query OK, 1 row affected (0.00 sec)
mysql> insert into usr (nome,data) values('baby',CURDATE());
Query OK, 1 row affected (0.00 sec)
mysql> select * from usr;
+----+---------+------------+
| id | nome | data |
+----+---------+------------+
| 1 | andre | 1990-04-07 |
| 2 | marcelo | 1994-03-31 |
| 3 | baby | 2012-06-07 |
+----+---------+------------+
3 rows in set (0.00 sec)
mysql> select * from usr where month(data) = 4;
+----+-------+------------+
| id | nome | data |
+----+-------+------------+
| 1 | andre | 1990-04-07 |
+----+-------+------------+
1 row in set (0.00 sec)
mysql> select * from usr where month(data) > 3;
+----+-------+------------+
| id | nome | data |
+----+-------+------------+
| 1 | andre | 1990-04-07 |
| 3 | baby | 2012-06-07 |
+----+-------+------------+
2 rows in set (0.00 sec)
mysql> select * from usr where month(data) = 3 or month(data) = 6;
+----+---------+------------+
| id | nome | data |
+----+---------+------------+
| 2 | marcelo | 1994-03-31 |
| 3 | baby | 2012-06-07 |
+----+---------+------------+
2 rows in set (0.00 sec)
mysql> select * from pessoa where month(data) = 4 AND year(data) = 1990;
+----+-------+------------+
| id | nome | data |
+----+-------+------------+
| 2 | andre | 1990-04-07 |
+----+-------+------------+
1 row in set (0.00 sec)
mysql> insert into usr (nome,data) values('people','1995-09-20');
Query OK, 1 row affected (0.00 sec)
mysql> select * from usr;
+----+---------+------------+
| id | nome | data |
+----+---------+------------+
| 1 | andre | 1990-04-07 |
| 2 | marcelo | 1994-03-31 |
| 3 | baby | 2012-06-07 |
| 4 | people | 1995-09-20 |
+----+---------+------------+
4 rows in set (0.00 sec)
mysql> select * from pessoa where month(data) = 4 AND year(data) = 1990;
+----+-------+------------+
| id | nome | data |
+----+-------+------------+
| 2 | andre | 1990-04-07 |
+----+-------+------------+
1 row in set (0.00 sec)
mysql> select * from usr where year(data) > 1990 AND year(data) < 2012;
+----+---------+------------+
| id | nome | data |
+----+---------+------------+
| 2 | marcelo | 1994-03-31 |
| 4 | people | 1995-09-20 |
+----+---------+------------+
2 rows in set (0.00 sec)
Its share
Mysql / LOAD DATA INFILE
mysql> LOAD DATA INFILE 'file.db.txt' INTO TABLE nameTABLE FIELDS TERMINATED BY '\t';