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.
精彩评论