For example, another way which may prove to be a better alternative for obtaining the uptime would be to source if directly from /proc/uptime (assuming that this interface is available to you)

I understand the sentiment here and often this approach makes sense but I don't think it does in this case.

The output from Solaris's stock uptime is close enough to GNU's that the regex would work without modification. So would IRIX's. And OpenBSD's. None of those systems has a /proc/uptime though. Using the tool in this case is far more portable.

As the uptime program is a stable enough tool that its interface is unlikely to change, using it probably should not be regarded as a maintenance risk either.

Getting your data from another program isn't inherently a bad thing. Nor should it to be shunned in lieu of any alternative. The key is to retrieve your data from an interface that is as stable and portable as possible. In this case, the data source he wanted to use is more standard than the one you suggested.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: Parsing 'uptime' output by sauoq
in thread Parsing 'uptime' output by Anonymous Monk

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.