Okay this original sub was taken from blootbot, and I needed it to format the strings better and worked it into this:
#!/usr/bin/perl -w use strict; open UPTIME, "/proc/uptime" or die "cannot open '/proc/uptime'.\n"; my $time = <UPTIME>; close UPTIME; $time = sprintf "%.0f", $time =~ /^(\d+)\./; print time2string($time), "\n"; sub time2string { my $time = shift; return if ! defined $time or $time !~ /^\-?\d+$/; my $prefix; if ($time < 0) { $time = - $time; $prefix = "- "; } my $s = $time % 60; my $m = ($time / 60) % 60; my $h = ($time / (60 * 60)) % 24; my $d = int($time / (24 * 60 * 60)); (my $y, $d) = modulus_thingamajig(365, $d); (my $mo, $d) = modulus_thingamajig(30, $d); (my $w, $d) = modulus_thingamajig(7, $d); my @data; push @data, sprintf "\002%d\002y", $y if $y != 0; push @data, sprintf "\002%d\002mo", $mo if $mo != 0; push @data, sprintf "\002%d\002w", $w if $w != 0; push @data, sprintf "\002%d\002d", $d if $d != 0; push @data, sprintf "\002%d\002h", $h if $h != 0; push @data, sprintf "\002%d\002m", $m if $m != 0; push @data, sprintf "\002%d\002s", $s if $s != 0 or ! @data; return $prefix . join ' ', @data; } sub modulus_thingamajig { my ($days, $d) = @_; my $return; if ($d >= $days) { $return = int($d / $days); $d = $d % $days; } else { $return = 0; } return ($return, $d); }
Any suggestions/tips on how it might be improved would be greatly appreciated. Thanks.

In reply to time2string by rendler

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.