I like oneliners but, please take a read of the recent Meditation covering pro and cons of oneliners.
For your curiosity you can cut a lot your Perl oneliner: the whole BEGIN { $sum = 0 }; is unneeded: without using strict you can freely use a variable even if not initialized so when you do $first_time_seen += 1; Perl knows that you want a number, if it is not initialized Perl choose 0 as wise precognition, then add 1 and all is good. Also ; is unneeded after a block declaration.
The chomp instruction too is unnecessary: you never print the name of the file, but anyway if in oneliner you are dealing with newlines -l switch is your friend! see perlrun.
You can also cheat to not type the END block at all using the eskimo greeting operator. If so the original oneliner becomes a lot shorter: something like:
perl -wne '$sum += (stat)[7]}{print "$sum\n"'
If you want to put the "human readable sizes" code the oneliner become suddenly fat and unfriendly: the best I arrived is, in the END created by the eskimo greeting:
@suf=qw(B KB MB GB TB);while($sum>=1024){$sum/=1024;shift @suf}prin +t $sum," ",shift @suf
L*
In reply to Re: One-liner's quoting and subroutine
by Discipulus
in thread One-liner's quoting and subroutine
by reisinge
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |