in reply to Re: Quarms with RegEx
in thread Quarms with RegEx

nice catch wise monk
if ($curline !~ /^#\s/ or $curline !~ /^\s/)
is logically equivalent to:
if (1)
because every string will either A.) not start with a '#' or B.) not start with a space.

Might I recommend a smarter regex rather than anding two simple ones together?

if ($curline !~ /^#?\s/)

-Blake

Replies are listed 'Best First'.
Re: Re: Re: Quarms with RegEx
by busunsl (Vicar) on Aug 28, 2001 at 12:57 UTC
    if ($curline !~ /^#?\s/)
    That will not work, because a domain line looks like:
    #domain1
    And that will not match your regex, so the condition is true, which is wrong.
      Ok, what am I missing here....
      #!/usr/bin/perl -w use strict; for ('#abc',' abc','abc','# abc',' #abc') { my $v1 = ($_ !~ /^#\s/ and $_ !~ /^\s/) || 0; # yours my $v2 = ($_ !~ /^#?\s/) || 0; # mine print "$v1 $v2 '$_'\n"; }
      Output:
      1 1 '#abc' 0 0 ' abc' 1 1 'abc' 0 0 '# abc' 0 0 ' #abc'

      -Blake

        Ahh, I see, you're right, I missed something in the original code.

        I think the original ($_ !~ /^#\s/ or $_ !~ /^\s/) was wrong in two ways:

        • First: the 'or' should be an 'and'
        • Second: I think the code should exclude domain-lines (#domain1) and empty lines.
        So it should have been $_ !~ /^#/ and $_ !~ /^\s/, which I had in mind and which can not be combined your way, but like /^[#\s]/ or <code>/^#|\s/.