===========================
文件内容的追加,覆盖(>>,>)
#!/usr/bin/perl
open ( readfile , "file4read.txt") or die ("Could not open the filen");
open ( writefile , ">b" );
while( $line = )
{
print writefile $line;
}
close( writefile );
close( readfile );
========================
文件打开判断
[root@localhost wangzm]# vi a1.sh
#!/usr/bin/perl
if (open(MYFILE, "b")) {
die ("here's what to do if the file opened successfully\n");
}
unless (open (MYFILE, "b")) {
die ("cannot open input file file1\n");
}
=======================
数组的应用
[root@localhost wangzm]# cat a1.sh
#!/usr/bin/perl
@array = (1, 2, 3, 4);
$array[3] = 5; # now @array is (1,2,3,5)
$array[6] = 17; # now @array is (1,2,3,5,"","",17);
print ("$array[0],$array[1],$array[2],$array[3],$array[4],$array[5],$array[6]\n")
[root@localhost wangzm]# ./a1.sh
1,2,3,5,,,17
==========================================
while 循环
[root@localhost wangzm]# cat a1.sh
#!/usr/bin/perl
$line = "abc";
$count = 1;
while ($count <= 3) {
print ("$line\n");
$line = "def";
$count++;
}
[root@localhost wangzm]# ./a1.sh
abc
def
def
===========================================
for循环
[root@localhost wangzm]# cat a1.sh
#!/usr/bin/perl
for ($line = "abc", $count = 1; $count <= 3; $line = "def", $count++) {
print ("$line\n");
}
[root@localhost wangzm]# ./a1.sh
abc
def
def
===========================================
阅读(1432) | 评论(0) | 转发(0) |