开发者

pattern searching in perl

开发者 https://www.devze.com 2023-03-16 21:46 出处:网络
use strict; use warnings; open(FILE1, \"/cygdrive/c/cpros/mola.txt\"); my $line = <FILE1>; print $line;
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

精彩评论

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