in Education by
I'm following @zdim's recursive solution in this question fastest way to sum the file sizes by owner in a directory to get my file sizes summed up by year-month perl -MFile::Find -E' use POSIX; $dir = shift // "."; find( sub { return if /^\.\.?$/; my ($mtime, $size) = (stat)[9,7]; my $yearmon = strftime "%Y%m",localtime($mtime); $rept{$yearmon} += $size ; }, $dir ); say ("$_ => $rept{$_} bytes") for sort keys %rept ' It gives results like this. 201701 => 7759 bytes 201702 => 530246 bytes 201703 => 3573094 bytes 201704 => 425827 bytes 201705 => 3637771 bytes 201706 => 2325391018 bytes 201707 => 127005 bytes 201708 => 2303 bytes 201709 => 231465431 bytes 201710 => 273667 bytes 201711 => 6397659 bytes 201712 => 333587 bytes 201802 => 874676 bytes 201803 => 147825681 bytes 201804 => 84971454 bytes 201805 => 3483547 bytes 201806 => 8004797 bytes 201807 => 184676 bytes 201808 => 1967947 bytes 201809 => 1592310 bytes 201810 => 24176 bytes 201811 => 883378 bytes 201812 => 6661592 bytes 201901 => 33979401 bytes But I need to include year-wise totals after printing all available months in a given year, like below 201710 => 1111 bytes 201711 => 2222 bytes 201712 => 3333 bytes 2017 => 6666 bytes ( summed up ) 201803 => 11111 bytes 201809 => 22222 bytes 2018 => 33333 bytes ( summed up ) How do I get that?. There might be blanks in a year-month and it need not end with month 12 for every year. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Two small changes will do the trick. perl -MFile::Find -E' use POSIX; $dir = shift // "."; find( sub { return if /^\.\.?\z/; # Fixed $ -> \z my ($mtime, $size) = (stat)[9,7]; my $yearmon = strftime "%Y%m",localtime($mtime); $rept{$yearmon} += $size; $rept{substr($yearmon, 0, 4)} += $size; # <--- }, $dir ); say "$_ => $rept{$_} bytes" for sort { "${a}99" cmp "${b}99" } keys %rept; # <--- '

Related questions

0 votes
    Can someone tell me any methods to read every line of a file in Python and store each line as an element in a ... till the end of list. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I am writing a Python script in Windows. I want to do something based on the file size. For example, if the ... I check the file size? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I looked into the Python os interface, but was unable to locate a method to move a file. How ... mv source_files destination_folder Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    How to copy a file in python? I already read this but found nothing. Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Anyone know any special function that appends to the file instead of overwriting it? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    We currently use multiple web servers accessing one MySQL server and fileserver. Looking at moving to the cloud, ... another solution? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I am getting an 'access is denied' error when I attempt to delete a folder that is not empty. I used the ... that is not empty? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Is there a way to get functionality similar to mkdir -p on the shell from within Python. I am looking for a ... has already written it? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I have an XML and would like to : sort on employeeNumber, and for each bookingtime by year, month ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    Which of the following input control represents a date consisting of a year and a month encoded according to ISO 8601 in Web ... - datetime B - datetime-local C - date D - month...
asked Dec 1, 2020 in Technology by JackTerrance
0 votes
    I am getting Facebook users' friends birthday back from Facebook in the following format: 10/07/1967 or ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    I am getting Facebook users' friends birthday back from Facebook in the following format: 10/07/1967 or ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    Find the probability that 5 Sundays occur in the month of November of a randomly selected year. Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    Period of natural degradation for cloth bags is (a) 2-3 weeks (b) 1 month (c) 5 months ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    The different variant of Date() constructor to create date object is/are ___________ i. new Date(date) ii ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
...