Hey guys, I have a command line I've been using to total the number of bytes in files, sorting by the day they were last modified. It takes piped input from a find command, that I in turn pipe into sort to get an easy to read list, e.g., find ./ -type f | perl ..perl stuff.. | sort

Here's the code I've been using:

perl -MData::Dumper -lne '@f=localtime((stat)[9]);$t{sprintf "%d%02d%0 +2d",$f[5]+1900,$f[4]+1,$f[3]}+=(stat)[7];END{print Dumper \%t}'

The goal is to simply print a list of dates and the total size of files modified on that day. Any output style that is readable and has the correct date in YYYYMMDD format is fine.

How can I shorten this a little?

Update: Thanks for everyone's input. There were a couple of comments that indicated that this may have been pretty pointless. I wasn't trying to improve flawed code or squeeze an extra 2% efficiency out of code that only runs once a week.

I was, however, looking for a few new things to add to the bag of tricks. I didn't know that END{} could be replaced by a simple}{, nor did I have any occasion to use the -s test switch for file sizes. I knew there must be a way to use either qw/1900 01 00/ or "19000100" to squeeze off a few more characters, but I couldn't see the solution (although hindsight is 20/20). Here's the code I ended up with, module-free and 40-odd characters squeezed off of the original command line, which originally included a find . -type f, and a final pipe to sort:

find .|perl -lne'$t{19000100+sprintf"%02d"x3,(localtime((stat)[9]))[5, +4,3]}+=-s if!-d}{print"$_ $t{$_}"for sort keys%t'

In reply to Golfing a size/date grabber by delirium

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.