# last语句示例
print ("DEMO of last .\n");
@arrayA = ("A","B","C","I");
$a =0;
foreach(@arrayA){
if($arrayA[$a]eq "B"){
print ("array element$a value is $arrayA[$a] .\n");
last;
}
$a ++;
print("after last. \n");
}
print("exit from block. \n");
# next语句示例
print ("DEMO of next .\n");
@arrayA = ("A","B","C","I");
$a =0;
foreach(@arrayA){
if($arrayA[$a] eq "B"){
print ("array element$a value is $arrayA[$a] .\n");
$a ++;
next;
}else {
print ("array element$a value is $arrayA[$a] .\n");
$a ++;
}
};
# redo 语句示例
print("What is your name? \n");
$name = <STDIN>; #标准输入,从键盘。
chop($name);
if (! length($name)) {
print("Msg: Zero length input. Please type your name .\n");
redo; #重新执行当前语句块
}
print("Thank you, " . uc($name) . "\n");
# goto 语句示例
#基本不用,不浪费时间写示例了。
指针ref
使用文件资源
文件操作比较简单,主要有:
打开文件:open、sysopen(与open模式相当,只是以文字方式进行文字模式的打开模式授权)
关闭文件:close
删除文件:unlink
重命名文件:rename
打开方式:
> or wCreates, Writes, and Truncates
>> or aWrites, Appends, and Creates
+< or r+Reads and Writes
+> or w+Reads, Writes, Creates, and Truncates
+>> or a+Reads, Writes, Appends, and Creates
目录操作:创建目录mkdir、删除目录rmdir、改变目录chdir等
opendir DIRHANDLE, EXPR # To open a directory
readdir DIRHANDLE # To read a directory
rewinddir DIRHANDLE # Positioning pointer to the begining
telldir DIRHANDLE # Returns current position of the dir
seekdir DIRHANDLE, POS # Pointing pointer to POS inside dir
closedir DIRHANDLE # Closing a directory.