Chinaunix首页 | 论坛 | 博客
  • 博客访问: 285638
  • 博文数量: 84
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -10
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-05 09:11
文章分类
文章存档

2015年(1)

2014年(6)

2013年(8)

2012年(1)

2011年(6)

2010年(2)

2009年(16)

2008年(44)

我的朋友

分类: LINUX

2008-07-24 17:51:38

===========================
文件内容的追加,覆盖(>>,>)
#!/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
===========================================
 
 
 
阅读(1402) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~