Two things:

  1. The construct (.+|) will match one or more of any character (".+")or nothing ("|)"). So if no value is given there, the regex will match on nothing and return that into $a. Nothing in this case is the empty string, which is not equivalent to undef. To test for this you could test for truth instead of definedness (if($a)), but it'd be much better to specify the fact that $a is optional with the explicit "?", i.e. (.+)? instead of (.+|). The same goes for the other places where you use "|)".
  2. Don't use the variables $a and $b like this, they are special variables (see perldoc perlvar) and you can run into strange errors when using them (or at least make your code hard to understand and maintain).
  3. Update: Check out bobfs excellent node True or False? A quick Reference Guide for more on this.


Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

In reply to Re: if var isnt used by tirwhan
in thread if var isnt used by metalfan

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.