Chinaunix首页 | 论坛 | 博客
  • 博客访问: 123661
  • 博文数量: 34
  • 博客积分: 1201
  • 博客等级: 少尉
  • 技术积分: 365
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-21 08:56
文章分类

全部博文(34)

文章存档

2012年(1)

2011年(15)

2010年(18)

我的朋友

分类:

2010-10-22 16:08:26

what 's the issue?
   chomp function can't assign to others variable.

for example:
# cat /tmp/a
a
d
g
f
# cat /tmp/b.pl
 

#!/usr/bin/perl
$file="/tmp/a";
@array=qw(a b c d);
open(FH,"$file") or die "couldn't open $file:$!";
foreach (<FH>) {
        $line=chomp($_);

        print "$line\n";
        foreach (@array) {
                $item=chomp($_);
                if ("$item" eq "$line" ){
                print "$line\n";
                }
        }
}

resulut:
1
1
1
1

what's the root cause?

   

#!/usr/bin/perl
$file="/tmp/a";
@array=qw(a b c d);
open(FH,"$file") or die "couldn't open $file:$!";
foreach () {
        chomp;
        $line = $_;
        foreach (@array) {
                chomp;
                $item=$_;
                if ("$item" eq "$line" ){
                print "$line\n";
                }
        }
}


note: The result of chomp can't assign to other variable
      $line = chomp($_);    #return value will be 1
阅读(857) | 评论(0) | 转发(0) |
0

上一篇:db2的安裝

下一篇:Outlook could not be open

给主人留下些什么吧!~~