Hi Sascha skasch,

Just to elaborate on the post from Hippo. When you use the comma operator, only the "truthfulness" of last comma part matters! Here is a simple example that attempts to demo that only the last comma part matters as far as the "if" is concerned although it does throw some warnings:

#!/usr/bin/perl use strict; use warnings; my $x = 2; if ($x < 0, $x >1){print "example1: ok, x>1\n";} if ($x > 1, $x <0) { print "example2: x is <0\n"; } else { print "example2: x is not <0\n"; } __END__ Useless use of numeric lt (<) in void context at C:\Projects_Perl\test +ing\CommaTruth.pl line 8. Useless use of numeric gt (>) in void context at C:\Projects_Perl\test +ing\CommaTruth.pl line 15. example1: ok, x>1 example2: x is not <0
A more real world example that you might see is something like this...a couple of actions happen, then a "truth" test happens.
#!/usr/bin/perl use strict; use warnings; my $input; while ( (print "some prompt: "), $input=<STDIN>, $input !~ /^\s*q(uit) +\s*/i) { print "I'm looping until you type q or quit\n"; } print "loop exited\n";
There are other ways to write this "while" condition. Typically this can be done with an "and" logical construction because print returns a true value. Here I am just demo'ing that all that matters is that final regex test of whether to quit or not.

In reply to Re: Cannot get Perl to match a specific string in my textfile by Marshall
in thread Cannot get Perl to match a specific string in my textfile by skasch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.