开发者

evaluating this boolean expression in perl [closed]

开发者 https://www.devze.com 2023-03-25 05:47 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

精彩评论

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

关注公众号