开发者

pattern searching in perl

use strict; 
use warnings;

open(FILE1, "/cygdrive/c/cpros/mola.txt");
my $line = <FILE1>;
print $line;
close(FILE1);
open(FILE1, ">/cygdrive/c/cpros/mola.txt");

if ($line = ~ /karthik/)
{
  print FILE1 ("1");
}
else
{
  print FILE1 ("0");
}

close(FILE1);

I have stored hello world in mola.txt file but still its printing 1 but the patt开发者_StackOverflow社区ern karthik is not saved in file but why its printing 1 ? how to make search patterns?


=~ is a separate operator, so it shouldn't have whitespace between its characters. With the whitespace, the condition of the if statement becomes an assignment that always yields true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜