您的位置:首页 > 其它

tcl ,perl 脚本语言简单入门

2016-07-20 10:32 597 查看
[root@BDI2 ~]# su - hzadmin
[hzadmin@BDI2 ~]$ ll
total 68
drwxrwxr-x 2 hzadmin hzadmin 40960 Jul 19 09:13 bj_data
-rw------- 1 hzadmin hzadmin    26 Sep 28  2015 dead.letter
-rw-rw-r-- 1 hzadmin hzadmin   182 Oct 15  2015 log.txt
drwxrwxr-x 2 hzadmin hzadmin 12288 Jul 20 03:23 test
drwxrwxr-x 2 hzadmin hzadmin    44 Oct 29  2015 trydemo
drwxrwxr-x 2 hzadmin hzadmin    29 Jul 19 15:17 t_user
drwxrwxr-x 5 hzadmin hzadmin    64 Jul 16  2015 urlAPP
drwxrwxr-x 2 hzadmin hzadmin    20 Jul 20 10:17 yc_test
[hzadmin@BDI2 ~]$ cd yc_test/
[hzadmin@BDI2 yc_test]$ ll
total 4
-rw-rw-r-- 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl
[hzadmin@BDI2 yc_test]$ pwd
/dfs/ftp/hzadmin/yc_test
[hzadmin@BDI2 yc_test]$ exit;
logout
[root@BDI2 ~]# cd /dfs/ftp/hzadmin/yc_test
[root@BDI2 yc_test]# ll
total 4
-rw-rw-r-- 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl
[root@BDI2 yc_test]# chmod a+x pro.tcl
[root@BDI2 yc_test]# ll
total 4
-rwxrwxr-x 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl
[root@BDI2 yc_test]# ./pro.tcl
Hello, world!
[root@BDI2 yc_test]# cat pro.tcl
#!/usr/bin/tclsh
puts "Hello, world!"
[root@BDI2 yc_test]# ll
total 4
-rwxrwxr-x 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl
[root@BDI2 yc_test]# cp pro.tcl sum.tcl
[root@BDI2 yc_test]# ll
total 8
-rwxrwxr-x 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl
-rwxr-xr-x 1 root    root    38 Jul 20 10:21 sum.tcl
[root@BDI2 yc_test]# vim sum.tcl
[root@BDI2 yc_test]# ll
total 8
-rwxrwxr-x 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl
-rwxr-xr-x 1 root    root    38 Jul 20 10:22 sum.tcl
[root@BDI2 yc_test]# ./sum.tcl
20
[root@BDI2 yc_test]# cat sum.tcl
#!/usr/bin/tclsh
puts [expr 1+4+6+9]

[root@BDI2 yc_test]# cp pro.tcl set.tcl
[root@BDI2 yc_test]# ll
total 12
-rwxrwxr-x 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl
-rwxr-xr-x 1 root    root    38 Jul 20 10:24 set.tcl
-rwxr-xr-x 1 root    root    38 Jul 20 10:22 sum.tcl
[root@BDI2 yc_test]# vim set.tcl
[root@BDI2 yc_test]# ./set.tcl
can't read "a=12": no such variable
while executing
"set a=12"
(file "./set.tcl" line 2)
[root@BDI2 yc_test]# vim set.tcl
[root@BDI2 yc_test]# ./set.tcl
12
[root@BDI2 yc_test]# cat set.tcl
#!/usr/bin/tclsh
set a 12
puts $a
[root@BDI2 yc_test]# tree
-bash: tree: command not found
[root@BDI2 yc_test]# ./pro.tcl
Hello, world!
[root@BDI2 yc_test]# cat pro.tcl
#!/usr/bin/tclsh
puts "Hello, world!"
[root@BDI2 yc_test]# ./sum.tcl
20
[root@BDI2 yc_test]# cat sum.tcl
#!/usr/bin/tclsh
puts [expr 1+4+6+9]

[root@BDI2 yc_test]#
[root@BDI2 yc_test]# ll
total 16
-rwxr-xr-x 1 root    root    304 Jul 20 10:58 for.tcl
-rwxrwxr-x 1 hzadmin hzadmin  38 Jul 20 10:17 pro.tcl
-rwxr-xr-x 1 root    root     34 Jul 20 10:25 set.tcl
-rwxr-xr-x 1 root    root     38 Jul 20 10:22 sum.tcl
[root@BDI2 yc_test]# ./for.tcl
Hello, world!
Hi my name is john
2:29:1987
wrong # args: should be "puts ?-nonewline? ?channelId? string"
while executing
"puts hi eval expression is called!"
("eval" body line 1)
invoked from within
"eval $foo"
(file "./for.tcl" line 14)
[root@BDI2 yc_test]# vim for.tcl

[root@BDI2 yc_test]# ./for.tcl
Hello, world!
Hi my name is john
2:29:1987
wrong # args: should be "puts ?-nonewline? ?channelId? string"
while executing
"puts 'hi eval expression is called'"
("eval" body line 1)
invoked from within
"eval $foo"
(file "./for.tcl" line 14)
[root@BDI2 yc_test]# vim for.tcl
[root@BDI2 yc_test]# ./for.tcl
Hello, world!
Hi my name is john
2:29:1987
wrong # args: should be "puts ?-nonewline? ?channelId? string"
while executing
"puts ? 'hi eval expression is called'"
("eval" body line 1)
invoked from within
"eval $foo"
(file "./for.tcl" line 14)
[root@BDI2 yc_test]# vim for.tcl
[root@BDI2 yc_test]# ./for.tcl
Hello, world!
Hi my name is john
2:29:1987
wrong # args: should be "puts ?-nonewline? ?channelId? string"
while executing
"puts ? hi eval expression is called"
("eval" body line 1)
invoked from within
"eval $foo"
(file "./for.tcl" line 14)
[root@BDI2 yc_test]# catfor.tcl
-bash: catfor.tcl: command not found
[root@BDI2 yc_test]# cat for.tcl
#!/usr/bin/tclsh
puts "Hello, world!"
#简单例子
set foo "john"
puts "Hi my name is $foo"

set month 2
set day 29
set year 1987
set date "$month:$day:$year"
puts $date

set foo "puts ? hi eval expression is called"
eval $foo
for {set i 0} {$i < 10} {incr i 1} {
puts "In the for loop, and i == $i"
}
[root@BDI2 yc_test]# vim for.tcl
[root@BDI2 yc_test]# cat for.tcl
#!/usr/bin/tclsh
puts "Hello, world!"
#简单例子
set foo "john"
puts "Hi my name is $foo"

set month 2
set day 29
set year 1987
set date "$month:$day:$year"
puts $date

#not work !!!
#set foo "puts ? hi eval expression is called"
#eval $foo
for {set i 0} {$i < 10} {incr i 1} {
puts "In the for loop, and i == $i"
}
[root@BDI2 yc_test]# ./for.tcl
Hello, world!
Hi my name is john
2:29:1987
In the for loop, and i == 0
In the for loop, and i == 1
In the for loop, and i == 2
In the for loop, and i == 3
In the for loop, and i == 4
In the for loop, and i == 5
In the for loop, and i == 6
In the for loop, and i == 7
In the for loop, and i == 8
In the for loop, and i == 9
[root@BDI2 yc_test]#
[root@cdh1 work]# cat per-test-2.pl
#!/usr/bin/perl
#	子程序
#	#	@_ 符号包含所有传递给子程序的参数
sub subFunc1 {
print "\nsubroutine 1\n";
}
sub subFunc2 {
print "subroutine 2\n";
return "I like Perl.\n";
}
sub subFunc3 {
my ($param1, $param2) = @_;
print $param1, $param2, "\n";
}
# calling subroutine
subFunc1();
#	或者
&subFunc1;
print subFunc2();
subFunc3("Ooops...", 123);
#	正则表达式
#	查找:在$re_test中查找oo
#	=~是绑定操作符
my $re_test = "Google";
if($re_test =~ /oo/) {
print "Bingo!\n";
}
#	替换;在$re_test中用xx替换oo
if($re_test =~ s/oo/xx/){
print $re_test, "\n";
}
#	匹配修饰符
#	i, g
my $re_test2 = "FacebOok";
if($re_test2 =~ /oo/i){
print "Bingo!\n";
}

[root@cdh1 work]# cp per-test-2.pl per-test-3.pl
[root@cdh1 work]# cat per-test-3.pl
#!/usr/bin/perl
#	子程序
#	#	@_ 符号包含所有传递给子程序的参数
sub subFunc1 {
print "\nsubroutine 1\n";
}
sub subFunc2 {
print "subroutine 2\n";
return "I like Perl.\n";
}
sub subFunc3 {
my ($param1, $param2) = @_;
print $param1, $param2, "\n";
}
# calling subroutine
subFunc1();
#	或者
&subFunc1;
print subFunc2();
subFunc3("Ooops...", 123);
#	正则表达式
#	查找:在$re_test中查找oo
#	=~是绑定操作符
my $re_test = "Google";
if($re_test =~ /oo/) {
print "Bingo!\n";
}
#	替换;在$re_test中用xx替换oo
if($re_test =~ s/oo/xx/){
print $re_test, "\n";
}
#	匹配修饰符
#	i, g
my $re_test2 = "FacebOok";
if($re_test2 =~ /oo/i){
print "Bingo!\n";
}

[root@cdh1 work]# vim per-test-3.pl
[root@cdh1 work]# ./ per-test-3.pl
bash: ./: is a directory
[root@cdh1 work]# ./per-test-3.pl

subroutine 1

subroutine 1
subroutine 2
I like Perl.
Ooops...123
Bingo!
Gxxgle
Bingo!
[root@cdh1 work]# cat per-test-3.pl
#!/usr/bin/perl
#	子程序
#	#	@_ 符号包含所有传递给子程序的参数
sub subFunc1 {
print "\nsubroutine 1\n";
}
sub subFunc2 {
print "subroutine 2\n";
return "I like Perl.\n";
}
sub subFunc3 {
my ($param1, $param2) = @_;
print $param1, $param2, "\n";
}
# calling subroutine
subFunc1();
#	或者
&subFunc1;
print subFunc2();
subFunc3("Ooops...", 123);
#	正则表达式
#	查找:在$re_test中查找oo
#	=~是绑定操作符
my $re_test = "Google";
if($re_test =~ /oo/) {
print "Bingo!\n";
}
#	替换;在$re_test中用xx替换oo
if($re_test =~ s/oo/xx/){
print $re_test, "\n";
}
#	匹配修饰符
#	i, g
my $re_test2 = "FacebOok";
if($re_test2 =~ /oo/i){
print "Bingo!\n";
}
if($re_test2 =~ /oo/){
print "Bingo!\n";
}

[root@cdh1 work]# cp per-test-3.pl per-test-4.pl
[root@cdh1 work]# cat per-test-3.pl
#!/usr/bin/perl
#	子程序
#	#	@_ 符号包含所有传递给子程序的参数
sub subFunc1 {
print "\nsubroutine 1\n";
}
sub subFunc2 {
print "subroutine 2\n";
return "I like Perl.\n";
}
sub subFunc3 {
my ($param1, $param2) = @_;
print $param1, $param2, "\n";
}
# calling subroutine
subFunc1();
#	或者
&subFunc1;
print subFunc2();
subFunc3("Ooops...", 123);
#	正则表达式
#	查找:在$re_test中查找oo
#	=~是绑定操作符
my $re_test = "Google";
if($re_test =~ /oo/) {
print "Bingo!\n";
}
#	替换;在$re_test中用xx替换oo
if($re_test =~ s/oo/xx/){
print $re_test, "\n";
}
#	匹配修饰符
#	i, g
my $re_test2 = "FacebOok";
if($re_test2 =~ /oo/i){
print "Bingo!\n";
}
if($re_test2 =~ /oo/){
print "Bingo!\n";
}

[root@cdh1 work]# vim per-test-4.pl
[root@cdh1 work]# ls -l per-test-4.pl
-rwxr-xr-x 1 root root 805 Jul 19 02:40 per-test-4.pl
[root@cdh1 work]# ./per-test-4.pl
[root@cdh1 work]# echo 12,34  45 6767 78978>>1.txt
bash: 78978: Bad file descriptor
[root@cdh1 work]# echo 1234  45 6767 78978>>1.txt
bash: 78978: Bad file descriptor
[root@cdh1 work]# touch 1.txt
[root@cdh1 work]# ll
total 20
-rw-r--r-- 1 root root   0 Jul 19 02:42 1.txt
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 711 Jul 19 02:11 per-test-2.pl
-rwxr-xr-x 1 root root 756 Jul 19 02:26 per-test-3.pl
-rwxr-xr-x 1 root root 805 Jul 19 02:40 per-test-4.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# echo 1234  45 6767 78978>>1.txt
bash: 78978: Bad file descriptor
[root@cdh1 work]# echo 1234 45 6767 78978>>1.txt
bash: 78978: Bad file descriptor
[root@cdh1 work]# vim 1.txt
[root@cdh1 work]# ./per-test-4.pl
1
2
3
4
5
6
7
8
9
10
1234
45
6767
78978
[root@cdh1 work]# cat per-test-4.pl
#!/usr/bin/perl

#	open()函数打开一个文件
#	#	读文件$file,将文件的标识符附给$fileHandle
my $file2open="./1.txt";
my $fileHandle;
open($fileHandle, "<$file2open");
#	#	<>符号用于读取$fileHandle指向的内容
#	#	利用钻石操作符号<>,你可以:
#	#	1. 将$fileHandle指向的内容附给一个标量,这样只读一行就over
#	#	my $line = <$fileHandle>;
#	#	2. 将$fileHandle指向的内容附给一个数组,将每一行作为一个element
#	#	my @lines = <$fileHandle>;
#	#	3. 常用于while或者foreach
foreach (<$fileHandle>) {
print $_;
}
#		#	写文件$file
#		open($fileHandle, ">$file2open");
#		print $fileHandle "abc";
#		#	追加写入
#		open($fileHandle, ">>$file2open");
#		print $fileHandle "def";
#		#	关闭文件
close($fileHandle);
[root@cdh1 work]# vim per-test-4.pl
[root@cdh1 work]# ./per-test-4.pl
1
2
3
4
5
6
7
8
9
10
1234
45
6767
78978
[root@cdh1 work]# ./per-test-4.pl
abc[root@cdh1 work]# ./per-test-4.pl
abc[root@cdh1 work]# ./per-test-4.pl
abc[root@cdh1 work]# vim per-test-4.pl
[root@cdh1 work]# ./per-test-4.pl
abc[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# cat per-test-4.pl
#!/usr/bin/perl

#	open()函数打开一个文件
#	#	读文件$file,将文件的标识符附给$fileHandle
my $file2open="./1.txt";
my $fileHandle;
open($fileHandle, "<$file2open");
#	#	<>符号用于读取$fileHandle指向的内容
#	#	利用钻石操作符号<>,你可以:
#	#	1. 将$fileHandle指向的内容附给一个标量,这样只读一行就over
#	#	my $line = <$fileHandle>;
#	#	2. 将$fileHandle指向的内容附给一个数组,将每一行作为一个element
#	#	my @lines = <$fileHandle>;
#	#	3. 常用于while或者foreach
foreach (<$fileHandle>) {
print $_;
}
#		#	写文件$file
open($fileHandle, ">$file2open");
print $fileHandle "abc";
#		#	追加写入
open($fileHandle, ">>$file2open");
print $fileHandle "def";
#		#	关闭文件
close($fileHandle);
[root@cdh1 work]# vim per-test-4.pl
[root@cdh1 work]# cat per-test-4.pl
#!/usr/bin/perl

#	open()函数打开一个文件
#	#	读文件$file,将文件的标识符附给$fileHandle
my $file2open="./1.txt";
my $fileHandle;
open($fileHandle, "<$file2open");
#	#	<>符号用于读取$fileHandle指向的内容
#	#	利用钻石操作符号<>,你可以:
#	#	1. 将$fileHandle指向的内容附给一个标量,这样只读一行就over
#	#	my $line = <$fileHandle>;
#	#	2. 将$fileHandle指向的内容附给一个数组,将每一行作为一个element
#	#	my @lines = <$fileHandle>;
#	#	3. 常用于while或者foreach
foreach (<$fileHandle>) {
print $_;
}
#		#	写文件$file
#open($fileHandle, ">$file2open");
#print $fileHandle "abc";
#		#	追加写入
open($fileHandle, ">>$file2open");
print $fileHandle "def";
#		#	关闭文件
close($fileHandle);
[root@cdh1 work]# ./per-test-4.pl
abcdef[root@cdh1 work]# ./per-test-4.pl
abcdefdef[root@cdh1 work]# ./per-test-4.pl
abcdefdefdef[root@cdh1 work]# ./per-test-4.pl
abcdefdefdefdef[root@cdh1 work]# ./per-test-4.pl
abcdefdefdefdefdef[root@cdh1 work]#
[root@cdh1 work]#
[root@cdh1 work]# vim foeach.pl
[root@cdh1 work]# ll
total 28
-rw-r--r-- 1 root root  21 Jul 19 03:04 1.txt
-rw-r--r-- 1 root root 449 Jul 19 03:13 foeach.pl
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 711 Jul 19 02:11 per-test-2.pl
-rwxr-xr-x 1 root root 756 Jul 19 02:26 per-test-3.pl
-rwxr-xr-x 1 root root 799 Jul 19 03:04 per-test-4.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# chmod a+x foeach.pl
[root@cdh1 work]# ll
total 28
-rw-r--r-- 1 root root  21 Jul 19 03:04 1.txt
-rwxr-xr-x 1 root root 449 Jul 19 03:13 foeach.pl
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 711 Jul 19 02:11 per-test-2.pl
-rwxr-xr-x 1 root root 756 Jul 19 02:26 per-test-3.pl
-rwxr-xr-x 1 root root 799 Jul 19 03:04 per-test-4.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# ./foeach.pl
OK1
OK2
while ... 10
while ... 9
while ... 8
while ... 7
while ... 6
while ... 5
while ... 4
while ... 3
while ... 2
while ... 1
1
2
3
a
[root@cdh1 work]# cat foeach.pl
#!/usr/bin/perl
my $isOK = 1;
if ($isOK) {	#	()和{}在这里都是必须使用的
print "OK1\n";
} else {
print "Ooops1...\n";
}
#	或者这样写:
print "OK2\n" if $isOK;
#	while
my $count = 10;
while($count > 0) {
print "while ... $count\n";
$count -= 1;
}
#	因为foreach的存在,for在Perl中用得很少,它的写法和C一样
my @array = (1, 2, 3, "a");
foreach my $elm (@array) {
print $elm, "\n";
}
[root@cdh1 work]# cp foeach.pl hash.pl
[root@cdh1 work]# vim hash.pl
[root@cdh1 work]# ll
total 32
-rw-r--r-- 1 root root  21 Jul 19 03:04 1.txt
-rwxr-xr-x 1 root root 449 Jul 19 03:13 foeach.pl
-rwxr-xr-x 1 root root 779 Jul 19 03:18 hash.pl
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 711 Jul 19 02:11 per-test-2.pl
-rwxr-xr-x 1 root root 756 Jul 19 02:26 per-test-3.pl
-rwxr-xr-x 1 root root 799 Jul 19 03:04 per-test-4.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# ./hash.pl
Unrecognized character \xE6 in column 2 at ./hash.pl line 3.
[root@cdh1 work]# vim hash.pl
[root@cdh1 work]# cat hash.pl
#!/usr/bin/perl
@var_array = (1, 2, 3, "a", "b", "c");
#或者
#	@var_array = qw(1 2 3 a b c);
#	#	或者
#	@var_array = qw/1 2 3 a b c/;
print "The 2nd elm of var_array is $var_array[1]\n";
#	#	数组切片
#	#	1. 输出数组中某两个值
print @var_array[0, 2], "\n";
#	#	2. 用连接符..输出数组中一个区间中的所有值
print @var_array[0..3], "\n";
#	#	用%后接变量名表示一个哈希,即"键值对"的集合
#	#	=> 符号左边是键,右边是值
%var_hashes = (a => "Apple", b => "Blizzard");
print "One elm of var_hashes is $var_hashes{\"b\"}\n";
#	#	用keys()或values()两个函数分别获取哈希表的所有键或所有值
my @allKeys = keys %var_hashes;
my @allValues = values %var_hashes;
print @allKeys;
print @allValues;
[root@cdh1 work]# ./hash.pl
The 2nd elm of var_array is 2
13
123a
One elm of var_hashes is Blizzard
abAppleBlizzard[root@cdh1 work]# vim hash.pl
[root@cdh1 work]# ./hash.pl
The 2nd elm of var_array is 2
13
123a
One elm of var_hashes is Blizzard
ab
AppleBlizzard
[root@cdh1 work]# cat hash.pl
#!/usr/bin/perl
@var_array = (1, 2, 3, "a", "b", "c");
#或者
#	@var_array = qw(1 2 3 a b c);
#	#	或者
#	@var_array = qw/1 2 3 a b c/;
print "The 2nd elm of var_array is $var_array[1]\n";
#	#	数组切片
#	#	1. 输出数组中某两个值
print @var_array[0, 2], "\n";
#	#	2. 用连接符..输出数组中一个区间中的所有值
print @var_array[0..3], "\n";
#	#	用%后接变量名表示一个哈希,即"键值对"的集合
#	#	=> 符号左边是键,右边是值
%var_hashes = (a => "Apple", b => "Blizzard");
print "One elm of var_hashes is $var_hashes{\"b\"}\n";
#	#	用keys()或values()两个函数分别获取哈希表的所有键或所有值
my @allKeys = keys %var_hashes;
my @allValues = values %var_hashes;
print @allKeys,"\n";
print @allValues,"\n";
[root@cdh1 work]#

[root@cdh1 Desktop]# cd /usr/local/
[root@cdh1 local]# ll
total 59660
drwxr-xr-x   6 root   root     4096 Jun 15 07:57 apache-maven-3.3.9
drwxr-xr-x.  2 root   root     4096 Jul  1 00:21 bin
drwxrwxr-x  11   1000 1000     4096 Jul  1 01:49 Django-1.9.7
drwxr-xr-x.  2 root   root     4096 Sep 23  2011 etc
drwxr-xr-x   2 root   root     4096 Jun 15 07:49 flume
drwxr-xr-x.  2 root   root     4096 Sep 23  2011 games
drwxr-xr-x  15 root   root     4096 Jun 13  2015 hadoop
drwxr-xr-x  10   1106  592     4096 Jul  3 19:31 hive
-rw-r--r--   1 root   root    82038 Jul 12 02:58 hive-site.xml
-rwxr-xr-x   1 root   root 61603840 Jul 12 02:53 hive.tar
drwxr-xr-x.  4 root   root     4096 Jun 30 18:31 include
drwxr-xr-x   8 uucp    143     4096 Jul 30  2014 jdk
drwxr-xr-x.  5 root   root     4096 Jun 30 23:49 lib
drwxr-xr-x.  2 root   root     4096 Sep 23  2011 libexec
drwxr-xr-x  10 109965 5000     4096 Jun 16 04:46 protobuf
drwxr-xr-x   6 root   root     4096 Jun 30 22:41 python
drwxr-xr-x   6 root   root     4096 Jul  1 00:11 python3
drwxr-xr-x.  2 root   root     4096 Sep 23  2011 sbin
drwxr-xr-x.  5 root   root     4096 Sep  9  2013 share
drwxr-xr-x   3 root   root     4096 Jul 15 03:05 shell-test
-rw-r--r--   1 root   root       14 Jul  4  2015 slaves
drwxr-xr-x.  2 root   root     4096 Jun 16 16:12 src
drwxr-xr-x   2 root   root     4096 Jul 18 20:21 work
[root@cdh1 local]# cd work/
[root@cdh1 work]# ll
total 8
-rwxr-xr-x 1 root root 48 Jul 18 20:20 per-test.pl
-rwxr-xr-x 1 root root 48 Jul 18 20:11 test.pl
[root@cdh1 work]# cp per-test.pl per-test-1.pl
[root@cdh1 work]# cp per-test.pl per-test-2.pl
[root@cdh1 work]# cp per-test.pl per-test-3.pl
[root@cdh1 work]# cp per-test.pl per-test-4.pl
[root@cdh1 work]# cp per-test.pl per-test-5.pl
[root@cdh1 work]# cp per-test.pl per-test-6.pl
[root@cdh1 work]# cp per-test.pl per-test-7.pl
[root@cdh1 work]# cp per-test.pl per-test-8.pl
[root@cdh1 work]# cp per-test.pl per-test-9.pl
[root@cdh1 work]# cp per-test.pl per-test-10.pl
[root@cdh1 work]# vim per-test.pl

[2]+  Stopped                 vim per-test.pl
[root@cdh1 work]# vim per-test.pl

[3]+  Stopped                 vim per-test.pl
[root@cdh1 work]# vim per-test-1.pl
[root@cdh1 work]# ./per-test-1.pl
Hello world.
Hello $var\nHello, world
Hello, world
1The scalar's value is 1
The scalar's value is1
The 2nd elm of var_array is 2
13
123a
[root@cdh1 work]# cat per-test-1.pl
#!/usr/bin/env perl
$var = "world.";
print "Hello $var\n";
#输出为:Hello world.
print 'Hello $var\n';
#输出为:Hello $var\n
#关于style
print("Hello, world\n");
#OK
print "Hello, world\n";
#OK
$var_scalar = 1;
print $var_scalar;
print "The scalar's value is $var_scalar\n";
print "The scalar's value is", $var_scalar, "\n";
@var_array = (1, 2, 3, "a", "b", "c");
#@var_array = qw(1 2 3 a b c);
#@var_array = qw/1 2 3 a b c/;
print "The 2nd elm of var_array is $var_array[1]\n";
print @var_array[0, 2], "\n";
print @var_array[0..3], "\n";

[root@cdh1 work]# ll
total 48
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-10.pl
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-2.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-3.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-4.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-5.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-6.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-7.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-8.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-9.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# rm -rf per-test-10.pl
[root@cdh1 work]# ll
total 44
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-2.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-3.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-4.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-5.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-6.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-7.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-8.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-9.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# rm -rf per-test-9.pl
[root@cdh1 work]# ll
total 40
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-2.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-3.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-4.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-5.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-6.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-7.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-8.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# ll
total 40
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-2.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-3.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-4.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-5.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-6.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-7.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:26 per-test-8.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# cat per-test-1.pl
#!/usr/bin/env perl
$var = "world.";
print "Hello $var\n";
#输出为:Hello world.
print 'Hello $var\n';
#输出为:Hello $var\n
#关于style
print("Hello, world\n");
#OK
print "Hello, world\n";
#OK
$var_scalar = 1;
print $var_scalar;
print "The scalar's value is $var_scalar\n";
print "The scalar's value is", $var_scalar, "\n";
@var_array = (1, 2, 3, "a", "b", "c");
#@var_array = qw(1 2 3 a b c);
#@var_array = qw/1 2 3 a b c/;
print "The 2nd elm of var_array is $var_array[1]\n";
print @var_array[0, 2], "\n";
print @var_array[0..3], "\n";

[root@cdh1 work]# cat per-test-9.pl
cat: per-test-9.pl: No such file or directory
[root@cdh1 work]# cat per-test-8.pl
$var = "world.";
print "Hello $var\n";
#输出为:Hello world.
print 'Hello $var\n';
#输出为:Hello $var\n
#关于style
print("Hello, world\n");
#OK
print "Hello, world\n";
#OK
$var_scalar = 1;
print $var_scalar;
print "The scalar's value is $var_scalar\n";
print "The scalar's value is", $var_scalar, "\n";
@var_array = (1, 2, 3, "a", "b", "c");
#@var_array = qw(1 2 3 a b c);
#@var_array = qw/1 2 3 a b c/;
print "The 2nd elm of var_array is $var_array[1]\n";
print @var_array[0, 2], "\n";
print @var_array[0..3], "\n";

[root@cdh1 work]# rm -rf per-test-8.pl
[root@cdh1 work]# rm -rf per-test-7.pl
[root@cdh1 work]# rm -rf per-test-6.pl
[root@cdh1 work]# rm -rf per-test-5.pl
[root@cdh1 work]# rm -rf per-test-4.pl
[root@cdh1 work]# ll
total 20
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-2.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-3.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# rm -rf per-test-3.pl
[root@cdh1 work]# ll
total 16
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test-2.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# vim per-test-2.pl
[root@cdh1 work]# ll
total 16
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 711 Jul 19 02:11 per-test-2.pl
-rwxr-xr-x 1 root root 584 Jul 19 00:25 per-test.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# ./per-test-1.pl
Hello world.
Hello $var\nHello, world
Hello, world
1The scalar's value is 1
The scalar's value is1
The 2nd elm of var_array is 2
13
123a
[root@cdh1 work]# ./per-test.pl
./per-test.pl: line 1: =: command not found
./per-test.pl: line 2: print: command not found
./per-test.pl: line 4: print: command not found
./per-test.pl: line 7: syntax error near unexpected token `"Hello, world\n"'
./per-test.pl: line 7: `print("Hello, world\n");'
[root@cdh1 work]# rm -rf per-test.pl
[root@cdh1 work]# ll
total 12
-rwxr-xr-x 1 root root 604 Jul 19 00:27 per-test-1.pl
-rwxr-xr-x 1 root root 711 Jul 19 02:11 per-test-2.pl
-rwxr-xr-x 1 root root  48 Jul 18 20:11 test.pl
[root@cdh1 work]# ./test.pl
test   message!
[root@cdh1 work]# ./per-test-2.pl

subroutine 1

subroutine 1
subroutine 2
I like Perl.
Ooops...123
Bingo!
Gxxgle
Bingo!
[root@cdh1 work]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  perl tcl