I am trying to do this boolean expression in perl and my code is supposed to be like this
enter code here
开发者_如何学JAVA $flag = 0;
while (<INFILE>)
{
if(/name/ && $flag==0)
{
$flag = 1;
print "HELLO\n";
}
elsif($flag)
{
print "Bye\n";
My plan is to write something like this
flag=0
while<>
if(/name/ && !flag)
flag=1;
elsif(flag)
last;
So is there anything wrong in what i did in the code what i reproduced? Is this the way of declaring a true and false value in perl
Based on your comment below:
while (<>) {
$flag = 1 if /name/;
if ($flag) {
# do something
}
}
Or you can do:
while (<>) { last if /name/ }
while (<>) {
# do something
}
A simple answer is:
In Perl, 0 or '' is considered false. A non-zero number (1, 42, etc) or string of length greater than 0 ( 'true', 'foo' ) is considered true.
精彩评论