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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |