in reply to Re3: Parsing 'uptime' output
in thread Parsing 'uptime' output

I read that node and it contains one side of a debate about the merits of using three-argument open over two-argument open. In fact, it is Dominus's reply to tilly's node in which he made the statement that he "would be cautious about suggesting that people use it in any code whose use is meant to be portable."

It seems to me that tilly and I are actually falling on the same side of completely different debates. I frankly don't even see how that discussion applies to this case and I invite you to enlighten me.

I think tilly might agree with me if he were still here. Maybe not. I don't know. I wish he was here to speak for himself. Maybe someone should ask Dominus what he thinks as it was his node to which you linked.

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

Replies are listed 'Best First'.
Re5: Parsing 'uptime' output
by blakem (Monsignor) on Aug 19, 2002 at 16:19 UTC
    Perhaps my one line link could have used a bit more explanation, especially for those who weren't around for the original discussion....

    Two argument open() is badly designed because the second argument actually represents two vastly different types of data (MODE and FILENAME). Getting these two pieces of data from your head to the CPU involves gluing them together and then parsing them apart again. This co-mingled intermediate form is what tilly, Dominus, and Dan Bernstein are warning against.

    In the uptime case, the intermediate form is the english representation of a span of time. If you want your computer to tell you how many seconds its been up, asking it to stringify that information into an english phrase for you to reparse seems like the wrong path to me.

    Given the number of Updates: in this thread, parsing the english is actually somewhat tricky. Why go to all that trouble if your machine can just hand you the exact piece of data you're interested in?

    -Blake

      Thanks for the explanation. I agree with you but I still think the application of the principle in this case isn't merited.

      If you want your computer to tell you how many seconds its been up...

      Parsing it into seconds wasn't requested. I agree that it might be what was wanted. People often don't ask for what they really want. It is just as likely, however, that he wanted to display the English form on a web page or some such. In any case he wanted to collect the time, the number of users, and the load averages as well.

      The fact remains that using uptime to retrieve these pieces of information provides a relatively stable and convenient interface and is able to be parsed by the same regex on at least the several platforms that I tested and probably many more. It might be a little messy (like a lot of the world) but Perl excels at dealing with messiness.

      In defense of my Updates, all I can say is I got it right the first time but I retyped it wrong. Twice. I would have cut and pasted but I was using the console on a different machine. There really was no excuse for such sloppiness and I've put a link to the node on my home node as a reminder to myself to take my time and get it right. ;-)

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