I do not understand how the line consisting of dashes enter the if in which i (should only) have two numeric values.

The problem is that the regular expression in:

if($line2=~ m/(\d*)\s*([A-Z]*)\s*(\d*)-(\d*)/)
accepts anything that has at least one '-' in it. Remember that \d* accepts zero or more digits, and \s* accepts zero or more white-space characters, etc. So this regex will match zero or more digits, followed by zero or more white-space characters, followed by zero or more [A-Z] characters, etc. The only thing that has to be present is a '-' to get a match.

I suspect that you would be perfectly happy with:

if($line2=~ m/(\d+)\s*([A-Z]+)\s*(\d+)-(\d+)/)
where you are using the regex to do two things at once: (a) recognise the lines that contain the information you wish to process further, and (b) parse those lines to extract that information.

If you are supremely confident that (a) the file you are processing always contains correctly formed lines, and (b) that your code recognises those correctly formed lines, then all will be well. In general I think it is wise to check the lines that are being rejected by the regex and warn about any whose format is not recognised. It's extra work to start with, but can save your bacon if some huge file at some future date contains broken data or stuff in a form you haven't catered for.


In reply to Re: Argument "" isn't numeric in numeric le (<=) by gone2015
in thread Argument "" isn't numeric in numeric le (<=) by hotel

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.