Below the text area when posting you could have seen some tips on how to write a post. <code> tags would have been useful there. UPG: Or Markup in the Monastery could be a useful read.

For you problem ne compares two strings, which /^[+-]\d+$/ is not. It's a matching operation (it's actually m/EXPR/ but with / delimiters around the expression the m can be omitted), which you can use on a string with the binding operator =~ see Binding Operators. And you want to check that $VAR1 is a number before making a number comparison with it. So that's if ($VAR1 !~ /^[\-+]?\d+$/ || $VAR1 != 2).

The next problem: - has a special meaning in a character range, so you have to escape it with \. Putting it in the first place is actually an exception to that, because it isn't ambiguous, but you can escape your - nonetheless, better safe than sorry.

At last, since you seem to be discovering Perl, do turn on warnings and strict, don't wait until you find a bug.

UPG: and maybe unless could make your code easier to read. And I don't see why you would include negative numbers if you're only looking for values different than 2. So you could actually write unless ($VAR1 =~ /^\+?2$/) { do some stuff }


In reply to Re: if multiple conditions & Warinings.... by Eily
in thread if multiple conditions & Warinings.... by sami.strat

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.