perl 判断操作系统类型

[ 2008-06-16 14:48 | by 草山湖 ]
if ( $^O =~ /MSWin32/ ) {
    print "Windows\n";
} else {
    print "Not windows\n";
}

OOP 的 Perl 实现

[ 2008-06-12 23:30 | by 草山湖 ]
Perl 并不是严格的面向对象的语言,Jason Stajich 说:"Perl OO is a type of hack, but it works!" 实际上 Perl OOP 对于使用者来说并不复杂,因为只是添加了很少的几个语法。

要实现OOP,有三件事情要做:

   1. 要创建一个 class,就建立一个 package。
   2. 要创建一个 method, 就写一个subroutine。
   3. 要创建一个 object, 就使用 bless 语法把 referent 变成object。
Tags: ,

#如何调用
deleteFolder("test");

#Used to remove a directory which is not empty.
#the process function.
sub deleteFolder{
  my $path = $_[0];
  chdir $path;

  #get all the files in that directory.
  @_=<*>;
  for(@_){
    if(-d $_){
      #if the destination file is a directory, go recursion.
      deleteFolder($_);
    }else{
      unlink;
    }
  }

  #Go up and del the destination directory.
  chdir "../";
  rmdir $path;
}
 

Perl 文件及目录操作

[ 2008-06-12 12:43 | by 草山湖 ]
大多数程序都不是孤立的,它们与它们的环境相互作用。很多的程序也需要通过文件操作实现数据的存贮和交换。 文件句柄(file handle)是Perl程序中为程序和外部世界提供I/O连接的名称。建议全部使用大写字母以示与变量等的区别。特别地,也可以将 STDIN/STDOUT/STDERR也认为 是Perl的文件句柄,分别代表标准输入/标准输出/标准错误输出。

打开及关闭文件
Perl的文件操作与C语言极为相似。如:
open(FILENAME,"abc.txt");

该调用为读文件打开,若为写文件而打开,需在文件名前加上大于号:
open(FILENAME,">abc.txt");

若要追加至文件尾,可在文件名前加上两个大于号:
open(FILENAME,">>abc.txt");
Tags: , , ,

perl中文手册 chm 版

[ 2008-06-10 19:37 | by 草山湖 ]
perl中文手册
下载文件 (已下载 856 次)
Tags: , , ,
分页: 1/2 第一页 1 2 下页 最后页 [ 显示模式: 摘要 | 列表 ]