CHSHJ 发表于 2018-9-1 07:18:27

perl 字符串操作

字符串数组元素赋值:@tmp=qw(aaa bbb kkk 9000);相当于@tmp= (“aaa”, “bbb”,“kkk”,“9000);     字符串比较,绝不能用==,要用eq
$ vi tip.pl  #!/usr/bin/perl
  print"input:";
  while(chomp($input=)) {
  print"your input is $input \n";
  if ($input=="q") { print "choose q \n";last;}
   elsif ($input=='n') {print "input is $input \n";next;}
     else { print "input ok,try again\n";}
  print "input:";
   }
$ ./tip.pl  input:x
  your input is x
  choose q
     字符串用==是最常犯的错误
     即使是整形,也尽量用eq,少用==
while(chomp($input=))  {
  for($i=1,$found=0;$i
页: [1]
查看完整版本: perl 字符串操作