下载此文档

perl 语言语句.doc


文档分类:IT计算机 | 页数:约5页 举报非法文档有奖
1/ 5
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/ 5 下载此文档
文档列表 文档介绍
perl的语句都类似C
  If ( ) {
  }  else{
         }
  while (  ) {
  }
  for ($count=1; $count <= 5; $count++) {
    # statements inside the loop go here
  }
    if也不完全象C,C一条语句时可以去掉{} ,但perl的if必须要带{}
chomp($a=<>);
if ($a=5) print "ok";
[******@localhost perltest]$ ./
syntax error at ./ line 7, near ") print"
Execution of ./ aborted due pilation errors. 
   if ( ) { }elsif ( ) { } else { }       注意:是elsif不是elseif  
    until循环
  until (  ) {
  }
    foreach                针对数组每个元素的循环
#!/usr/bin/perl
***@tmp=qw(aaa bbb kkk 9000);
$i=0;
foreach $tt(***@tmp) {
 print "no.$i is $tt","\n";
 $i++;
}  
#!/usr/bin/perl
***@tmp=qw(aaa bbb kkk 9000);
for($i=0;$i<scalar(***@tmp);$i++) {
 print "no.$i is $tmp[$i] ","\n";
}
[******@localhost perltest]$ ./
is aaa
is bbb
is kkk
is 9000
[******@localhost perltest]$ ./
is aaa
is bbb
is kkk
is 9000
 
    循环控制,与C,SHELL完全不一样
last    循环结束    与C中的break作用相同
next    执行下一个循环    与C中的continue作用相同
redo    重复此次循环    PERL特有的一个命令
[******@localhost perltest]$ vi
#!/usr/bin/perl
print"input:";
$i=1;
while(chomp($input=<STDIN>)) {
print "no.$i ==>";
$i++;
if($input eq "q") { print "choose q \n";last;}
  elsif ($input eq 'n') {print "choose n next:";next;}
    elsif ($input eq 'r') {print "redo :";redo;}
      else { print "input ok \n";}
print "input:";
 

perl 语言语句 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数 5
  • 收藏数 0 收藏
  • 顶次数 0
  • 上传人 szh187166
  • 文件大小 0 KB
  • 时间2013-01-08
最近更新