haimei has asked for the wisdom of the Perl Monks concerning the following question:

My program requirs to read an input file with 3 columns(month dates, fileSize, fileName)in 3 steps: Here I only give 2 months dates in Julian order for simplifying the process.

1. count the total number of files loaded in each month.
2. count the total file size for each month.
3. count the largest file size in each month.

I do need help to correct my code; when I run it, it doesn't go to output file, and the output is not in individual month but in whol months. Really much appreciated for any help!

Here is my code:
#!/usr/bin/perl require strict; #require warning; #require Date::Manip; require Data::Dumper; require File::Find; require File::stat; #require sort 'stable'; my $filin = '/root/scripts/newsort.in'; my $fleot = '/root/scripts/results/sizeinfo.out'; open my $fh, $filin || die $!; open my $fot, ">$fleot" || die $!; ##Define month lengths @Janlen = ( '006', '007', '008', '009', '010', '011', '012', '013', '0 +14', '015', '016', '017', '018', '019', '020', '021', '022', '023', ' +024', '025', '026', '027', '028', '029', '030', '031' ); @Feblen = ( '032', '033', '034', '035', '036', '037', '038', '039', '0 +40', '041', '042', '043', '044', '045', '046', '047', '048', '049', ' +050', '051', '052', '053', '054', '055', '056', '057', '058', '059' ) +; #Define month hash %mthlens = (@Janlen, @Feblen); my @julens = %mthlens; my $julias = @julens; my $Janlias = @Janlen; my $Feblias = @Feblen; my $Marlias = @Marlen; while (%mthlens=<$fh>){ chomp; my %lengths = map { $_ => length $_ } %mthlens; while ( my ($Janlen,$length,$filename) = each %lengths) { @s = sort { $length{$b} <=> $length{$a}} keys %length; print join("\t", $Janlen, $length, $filename ), "\n"; } }

Replies are listed 'Best First'.
Re: count file size
by kcott (Archbishop) on Oct 10, 2013 at 04:55 UTC

    G'day haimei,

    Welcome to the monastery.

    I suspect your problem is one of precedence. See "||" and "or" in the precedence table in perlop. Also see the three-argument form of open.

    [I sent you a message regarding the unreadable nature of your post: please address this issue. I managed to recreate part of your post by looking at the markup. In addition to <code>...</code> tags around your code, please also put <p>...</p> tags around your paragraph text. Thankyou.]

    -- Ken

      Hi Ken! I have fixed the format on my most recent post. Could you help me to delete the unreadable one? As you may have noticed, this is my very first time posting on the forumn, and I have not yet find a way to delete my own post. Thank you for your quick response!

        Yes, I was aware this was your first post: hence the "Welcome to the monastery." in my original reply.

        In the message I sent to you about fixing your post, I included a link to "How do I change/delete my post?", which should explain what you're asking about.

        "Writeup Formatting Tips" (and pages linked from it) may also be of help.

        -- Ken