any pointers for a newbie

Top pointer: use sane indenting. If you had then it would be much clearer that $port is out of scope when you use it at line 48.

Try to provide an SSCCE. That way people can be better informed as to which of your 18 lines is line 48.

Also, arbitrary lines of data such as may be found in /etc/services do not necessarily make valid regular expressions, therefore you should not attempt to use them as such. Consider using split or a pattern match to extract only the port number.

There's no point in trying to analyse the comments in /etc/services, so skip them.

Wrap your error text in <code> tags so that others can read them.

HTH, Hippo


In reply to Re: Port check - Services File by hippo
in thread Port check - Services File by deelinux

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.