tcl ,perl 脚本语言简单入门

2016-07-20 11:15:41来源:CSDN作者:hzdxw人点击

[root@BDI2 ~]# su - hzadmin[hzadmin@BDI2 ~]$ lltotal 68drwxrwxr-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.txtdrwxrwxr-x 2 hzadmin hzadmin 12288 Jul 20 03:23 testdrwxrwxr-x 2 hzadmin hzadmin    44 Oct 29  2015 trydemodrwxrwxr-x 2 hzadmin hzadmin    29 Jul 19 15:17 t_userdrwxrwxr-x 5 hzadmin hzadmin    64 Jul 16  2015 urlAPPdrwxrwxr-x 2 hzadmin hzadmin    20 Jul 20 10:17 yc_test[hzadmin@BDI2 ~]$ cd yc_test/[hzadmin@BDI2 yc_test]$ lltotal 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]# lltotal 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]# lltotal 4-rwxrwxr-x 1 hzadmin hzadmin 38 Jul 20 10:17 pro.tcl[root@BDI2 yc_test]# ./pro.tclHello, world![root@BDI2 yc_test]# cat pro.tcl#!/usr/bin/tclshputs "Hello, world!"[root@BDI2 yc_test]# lltotal 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]# lltotal 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]# lltotal 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/tclshputs [expr 1+4+6+9][root@BDI2 yc_test]# cp pro.tcl set.tcl[root@BDI2 yc_test]# lltotal 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.tclcan'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.tcl12[root@BDI2 yc_test]# cat set.tcl#!/usr/bin/tclshset a 12puts $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/tclshputs "Hello, world!"[root@BDI2 yc_test]# ./sum.tcl20[root@BDI2 yc_test]# cat sum.tcl#!/usr/bin/tclshputs [expr 1+4+6+9][root@BDI2 yc_test]# 
[root@BDI2 yc_test]# lltotal 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 john2:29:1987wrong # 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 john2:29:1987wrong # 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 john2:29:1987wrong # 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 john2:29:1987wrong # 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/tclshputs "Hello, world!"#简单例子set foo "john"puts "Hi my name is $foo" set month 2set day 29set year 1987set date "$month:$day:$year"puts $date set foo "puts ? hi eval expression is called"eval $foofor {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/tclshputs "Hello, world!"#简单例子set foo "john"puts "Hi my name is $foo" set month 2set day 29set year 1987set date "$month:$day:$year"puts $date#not work !!! #set foo "puts ? hi eval expression is called"#eval $foofor {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 john2:29:1987In the for loop, and i == 0In the for loop, and i == 1In the for loop, and i == 2In the for loop, and i == 3In the for loop, and i == 4In the for loop, and i == 5In the for loop, and i == 6In the for loop, and i == 7In the for loop, and i == 8In 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 subroutinesubFunc1();#	或者&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, gmy $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 subroutinesubFunc1();#	或者&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, gmy $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.plbash: ./: is a directory[root@cdh1 work]# ./per-test-3.plsubroutine 1subroutine 1subroutine 2I like Perl.Ooops...123Bingo!GxxgleBingo![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 subroutinesubFunc1();#	或者&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, gmy $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 subroutinesubFunc1();#	或者&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, gmy $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.txtbash: 78978: Bad file descriptor[root@cdh1 work]# echo 1234  45 6767 78978>>1.txtbash: 78978: Bad file descriptor[root@cdh1 work]# touch 1.txt[root@cdh1 work]# lltotal 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.txtbash: 78978: Bad file descriptor[root@cdh1 work]# echo 1234 45 6767 78978>>1.txtbash: 78978: Bad file descriptor[root@cdh1 work]# vim 1.txt [root@cdh1 work]# ./per-test-4.pl123456789101234 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.pl123456789101234 45 6767 78978[root@cdh1 work]# ./per-test-4.plabc[root@cdh1 work]# ./per-test-4.plabc[root@cdh1 work]# ./per-test-4.plabc[root@cdh1 work]# vim per-test-4.pl[root@cdh1 work]# ./per-test-4.plabc[root@cdh1 work]# ./per-test-4.plabcdef[root@cdh1 work]# ./per-test-4.plabcdef[root@cdh1 work]# ./per-test-4.plabcdef[root@cdh1 work]# ./per-test-4.plabcdef[root@cdh1 work]# ./per-test-4.plabcdef[root@cdh1 work]# ./per-test-4.plabcdef[root@cdh1 work]# ./per-test-4.plabcdef[root@cdh1 work]# ./per-test-4.plabcdef[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.plabcdef[root@cdh1 work]# ./per-test-4.plabcdefdef[root@cdh1 work]# ./per-test-4.plabcdefdefdef[root@cdh1 work]# ./per-test-4.plabcdefdefdefdef[root@cdh1 work]# ./per-test-4.plabcdefdefdefdefdef[root@cdh1 work]# [root@cdh1 work]# [root@cdh1 work]# vim foeach.pl[root@cdh1 work]# lltotal 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]# lltotal 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 OK1OK2while ... 10while ... 9while ... 8while ... 7while ... 6while ... 5while ... 4while ... 3while ... 2while ... 1123a[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]# lltotal 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 213123aOne elm of var_hashes is BlizzardabAppleBlizzard[root@cdh1 work]# vim hash.pl [root@cdh1 work]# ./hash.pl The 2nd elm of var_array is 213123aOne elm of var_hashes is BlizzardabAppleBlizzard[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]# lltotal 59660drwxr-xr-x   6 root   root     4096 Jun 15 07:57 apache-maven-3.3.9drwxr-xr-x.  2 root   root     4096 Jul  1 00:21 bindrwxrwxr-x  11   1000 1000     4096 Jul  1 01:49 Django-1.9.7drwxr-xr-x.  2 root   root     4096 Sep 23  2011 etcdrwxr-xr-x   2 root   root     4096 Jun 15 07:49 flumedrwxr-xr-x.  2 root   root     4096 Sep 23  2011 gamesdrwxr-xr-x  15 root   root     4096 Jun 13  2015 hadoopdrwxr-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.tardrwxr-xr-x.  4 root   root     4096 Jun 30 18:31 includedrwxr-xr-x   8 uucp    143     4096 Jul 30  2014 jdkdrwxr-xr-x.  5 root   root     4096 Jun 30 23:49 libdrwxr-xr-x.  2 root   root     4096 Sep 23  2011 libexecdrwxr-xr-x  10 109965 5000     4096 Jun 16 04:46 protobufdrwxr-xr-x   6 root   root     4096 Jun 30 22:41 pythondrwxr-xr-x   6 root   root     4096 Jul  1 00:11 python3drwxr-xr-x.  2 root   root     4096 Sep 23  2011 sbindrwxr-xr-x.  5 root   root     4096 Sep  9  2013 sharedrwxr-xr-x   3 root   root     4096 Jul 15 03:05 shell-test-rw-r--r--   1 root   root       14 Jul  4  2015 slavesdrwxr-xr-x.  2 root   root     4096 Jun 16 16:12 srcdrwxr-xr-x   2 root   root     4096 Jul 18 20:21 work[root@cdh1 local]# cd work/[root@cdh1 work]# lltotal 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.plHello world.Hello $var/nHello, worldHello, world1The scalar's value is 1The scalar's value is1The 2nd elm of var_array is 213123a[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#关于styleprint("Hello, world/n");#OKprint "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]# lltotal 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]# lltotal 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]# lltotal 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]# lltotal 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#关于styleprint("Hello, world/n");#OKprint "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.plcat: 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#关于styleprint("Hello, world/n");#OKprint "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]# lltotal 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]# lltotal 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]# lltotal 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, worldHello, world1The scalar's value is 1The scalar's value is1The 2nd elm of var_array is 213123a[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]# lltotal 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 1subroutine 1subroutine 2I like Perl.Ooops...123Bingo!GxxgleBingo![root@cdh1 work]# 

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台