- 浏览: 2539077 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Perl Language(I)Beginning of Perl
1. About Perl
check my perl version
>perl -v
This is perl, v5.10.1 (*) built for i686-linux-gnu-thread-multi
(with 40 registered patches, see perl -V for more detail)
perl eclipse plugin
http://www.epic-ide.org/updates/
http://www.epic-ide.org/running_perl_scripts_within_eclipse/entry.htm
Create a perl project easyperl
Create a file with name Demo1.pl
[Run] ---->[Perl Local]
My first perl programme
>perl -e 'print "hello sillycat!\n"'
hello sillycat!
>vi ch1.pl
#!/usr/bin/perl
print "hello sillycat\n";
execute this programme
>perl ch1.pl
give the right to the file
>chmod a+x ch1.pl
>./ch1.pl
install the doc of perl
>sudo apt-get install perl-doc
>perldoc -f print
style of comments
#comments here
=begin
comments
=end
2. Scalar
2.1 numeric
>vi ch2_1.pl
#!/usr/bin/perl
$a = 1_300_300;
$b = 1.3e6;
print "$a\n"; # 1300300
print "$b\n"; # 13000000
2.2 string
>vi ch2_2.pl
#!/usr/bin/perl
$a = "perl";
$c = "在\tPerl\t中使用字串非常容易";
print "$a\n";
print "$c\n";
difference between '' and ""
$c = "在Perl中使用字串非常容易";
print '$c\n';
print "$c\n";
>vi ch2_3.pl
#!/usr/bin/perl
$a = 1357;
$b = 2468;
print $a+$b,"\n";
print $a.$b,"\n";
console output:
3825
13572468
>vi ch2_4.pl
#!/usr/bin/perl
use strict;
my $foo = 3;
$foo = 3 + (my $bar = 2);
print "$foo\n";
print "no message="."$bar\n";
>vi ch2_6.pl
#!/usr/bin/perl
#my $name;
my $name="sillycat";
if (defined($name)) {
print $name."\n";
} else {
print "it's undefined\n";
}
3. Array and List
>Demo1.pl in easyperl project
#!/usr/bin/perl
my @array;
$array[0] = "1";
print "first value = $array[0]\n";
my ($first, $second, $third) = (1,2,3);
print "second Value = $second\n";
my @array = qw/first second third/;
print "third Value = @array[2]\n";
my @array = (1...10);
my @array2 = (3, -1, @array, 13);
print "last Value = @array[9]\n";
print "last Value = @array2[1]\n";
console output:
first value = 1
second Value = 2
third Value = third
last Value = 10
last Value = -1
>Demo2.pl in easyperl project
#!/usr/bin/perl
my @array = qw{"first" "second" "third"};
$array[6] = "test";
print $array[6] . "\n";
print $#array . "\n"; # last index number of the array
$array[$#array + 1] = "last value";
print "Last Value:" . $array[$#array] . "\n"
console output:
test
6
Last Value:last value
3.3 push / pop
>Demo3.pl in easyperl project
#!/usr/bin/perl
my @array = qw{first second third};
print $#array . "\n";
push @array, 'fourth';
print $#array . "\n";
my $tmp = pop @array;
print $#array . " tmp=" . $tmp . "\n";
my @array2 = qw{'test1','test2'};
push @array, @array2;
print 'number of array:' . @array . "\n";
console output:
2
3
2 tmp=fourth
number of array:4
3.4 shift/unshift
>demo2.pl in easyperl project
#!/usr/bin/perl
my @array = (1...10);
print @array;
print "\n";
shift @array; # remove the first one
print @array;
print "\n";
unshift @array, 0; # put 0 to the first one
print @array;
console output:
12345678910
2345678910
02345678910
3.5 Part of the array
>demo4.pl in easyperl
#!/usr/bin/perl
my @array = (0...10);
my @array2 = @array[2...4];
print @array2;
print "\n";
my @array3 = @array[2...4,6];
print @array3;
print "\n";
my @array = (1...10);
my $scale = @array + 4;
print $scale;
print "\n";
my @scalar_array = ($scale,15);
print @scalar_array;
console output:
234
2346
14
1415
3.7.2 join
#!/usr/bin/perl
my @array = qw/-4 45 33 8 75/;
print join ',', @array;
print "\n";
print @array;
console output:
-4,45,33,8,75
-44533875
3.7.3 map
my @array = map { sqrt($_)*10 } qw/4 81/;
print join ',',@array;
console output:
20,90
3.7.4 grep
my @array = qw/-4 8 12 -22 19 -8 42/;
my @positive = grep {$_ > 0} @array;
print "$_\n" for @positive
console output:
8
12
19
42
references:
http://easun.org/perl/perl-toc/
http://perl.apache.org/
1. About Perl
check my perl version
>perl -v
This is perl, v5.10.1 (*) built for i686-linux-gnu-thread-multi
(with 40 registered patches, see perl -V for more detail)
perl eclipse plugin
http://www.epic-ide.org/updates/
http://www.epic-ide.org/running_perl_scripts_within_eclipse/entry.htm
Create a perl project easyperl
Create a file with name Demo1.pl
[Run] ---->[Perl Local]
My first perl programme
>perl -e 'print "hello sillycat!\n"'
hello sillycat!
>vi ch1.pl
#!/usr/bin/perl
print "hello sillycat\n";
execute this programme
>perl ch1.pl
give the right to the file
>chmod a+x ch1.pl
>./ch1.pl
install the doc of perl
>sudo apt-get install perl-doc
>perldoc -f print
style of comments
#comments here
=begin
comments
=end
2. Scalar
2.1 numeric
>vi ch2_1.pl
#!/usr/bin/perl
$a = 1_300_300;
$b = 1.3e6;
print "$a\n"; # 1300300
print "$b\n"; # 13000000
2.2 string
>vi ch2_2.pl
#!/usr/bin/perl
$a = "perl";
$c = "在\tPerl\t中使用字串非常容易";
print "$a\n";
print "$c\n";
difference between '' and ""
$c = "在Perl中使用字串非常容易";
print '$c\n';
print "$c\n";
>vi ch2_3.pl
#!/usr/bin/perl
$a = 1357;
$b = 2468;
print $a+$b,"\n";
print $a.$b,"\n";
console output:
3825
13572468
>vi ch2_4.pl
#!/usr/bin/perl
use strict;
my $foo = 3;
$foo = 3 + (my $bar = 2);
print "$foo\n";
print "no message="."$bar\n";
>vi ch2_6.pl
#!/usr/bin/perl
#my $name;
my $name="sillycat";
if (defined($name)) {
print $name."\n";
} else {
print "it's undefined\n";
}
3. Array and List
>Demo1.pl in easyperl project
#!/usr/bin/perl
my @array;
$array[0] = "1";
print "first value = $array[0]\n";
my ($first, $second, $third) = (1,2,3);
print "second Value = $second\n";
my @array = qw/first second third/;
print "third Value = @array[2]\n";
my @array = (1...10);
my @array2 = (3, -1, @array, 13);
print "last Value = @array[9]\n";
print "last Value = @array2[1]\n";
console output:
first value = 1
second Value = 2
third Value = third
last Value = 10
last Value = -1
>Demo2.pl in easyperl project
#!/usr/bin/perl
my @array = qw{"first" "second" "third"};
$array[6] = "test";
print $array[6] . "\n";
print $#array . "\n"; # last index number of the array
$array[$#array + 1] = "last value";
print "Last Value:" . $array[$#array] . "\n"
console output:
test
6
Last Value:last value
3.3 push / pop
>Demo3.pl in easyperl project
#!/usr/bin/perl
my @array = qw{first second third};
print $#array . "\n";
push @array, 'fourth';
print $#array . "\n";
my $tmp = pop @array;
print $#array . " tmp=" . $tmp . "\n";
my @array2 = qw{'test1','test2'};
push @array, @array2;
print 'number of array:' . @array . "\n";
console output:
2
3
2 tmp=fourth
number of array:4
3.4 shift/unshift
>demo2.pl in easyperl project
#!/usr/bin/perl
my @array = (1...10);
print @array;
print "\n";
shift @array; # remove the first one
print @array;
print "\n";
unshift @array, 0; # put 0 to the first one
print @array;
console output:
12345678910
2345678910
02345678910
3.5 Part of the array
>demo4.pl in easyperl
#!/usr/bin/perl
my @array = (0...10);
my @array2 = @array[2...4];
print @array2;
print "\n";
my @array3 = @array[2...4,6];
print @array3;
print "\n";
my @array = (1...10);
my $scale = @array + 4;
print $scale;
print "\n";
my @scalar_array = ($scale,15);
print @scalar_array;
console output:
234
2346
14
1415
3.7.2 join
#!/usr/bin/perl
my @array = qw/-4 45 33 8 75/;
print join ',', @array;
print "\n";
print @array;
console output:
-4,45,33,8,75
-44533875
3.7.3 map
my @array = map { sqrt($_)*10 } qw/4 81/;
print join ',',@array;
console output:
20,90
3.7.4 grep
my @array = qw/-4 8 12 -22 19 -8 42/;
my @positive = grep {$_ > 0} @array;
print "$_\n" for @positive
console output:
8
12
19
42
references:
http://easun.org/perl/perl-toc/
http://perl.apache.org/
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 465NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 328Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 428Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 376Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 462NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 413Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 330Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 242GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 443GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 320GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 306Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 310Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 284Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 302Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 276NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 254Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 564NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 255Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 356Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 362Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
programming biologist who needs to solve very specific problems., Beginning Perl for Bioinformatics is designed to get you quickly over the Perl language barrier by approaching programming as an ...
programming biologist who needs to solve very specific problems., Beginning Perl for Bioinformatics is designed to get you quickly over the Perl language barrier by approaching programming as an ...
Originally touted as the duct tape of the Internet, Perl has since evolved into a multipurpose, multiplatform language present absolutely everywhere: heavy-duty web applications, the cloud, systems ...
edition of Learning Perl. In the intervening years, Perl itself has grown substantially from a "cool" scripting language used primarily by Unix system administrators to a robust object-oriented ...
Making use of online Perl resources like CPAN First principles in programming and the Perl syntax Working with files and databases Writing web pages in Perl Using Perl as an object-oriented language
Table of Content.........................................................................................................................i Copyright......................................................
XML(eXtensible Markup Language)是一种用于标记数据的语言,广泛应用于数据交换、存储和结构化信息的处理。在数据库领域,XML由于其灵活性和可扩展性,被广泛用来整合异构系统中的数据,实现数据的标准化和共享。...
2. **[UNIX系统管理高手].Wrox.-.Beginning.Perl.pdf** - 尽管标题提到的是Perl编程,但Perl在UNIX环境中常被用来编写系统管理和维护脚本。这本书可能介绍了Perl的基础语法,以及如何利用Perl在UNIX系统上执行任务,...
JAVA模版引擎Freemarker常用标签(一) 1. if指令 这是一个典型的分支控制指令,该指令的作用完全类似于Java语言中的if,if指令的语法格式如下: <#if condition>... <#elseif condition>... <#elseif condition>......
mv [-f] [-i] f1 ... fn d1 mv [-f] [-i] d1 d2 mv 源文件名 目标文件名 若目标文件名还没有,则是源文件重命名为目标文件;若目标文件已存在,则源文件覆盖目标文件。 mv 源文件名 目标目录 移动文件 mv 源目录...