tag: OS data art for Re C
#! /Usr/bin/perl # Name: logcalc. PL # calc The amount of access urluse strict; Use warnings; Use diagnostics; Use File: basename; my ($ Arg, $ arg_only); my $ file; my ($ year, $ month, $ day, $ Mon); my ($ time, $ method, $ URL); my ($ amount, $ hour, $ key, $ value ); my (% part, % hash); my @ array; $ Arg = shift @ argv; $ arg_only = basename ($ Arg); @ array = Split/_/, $ arg_only; $ array [1] = ~ /^ (\ D {4}) (\ D {2}) (\ D {2}) $/; # Print $ &; $ year = $1; $ month = $2; $ day = $3; % hash = ("01" => "Jan", "02" => "FEB ", "03" => "Mar", "04" => "APR", "05" => "may", "06" => "Jun ", "07" => "Jul", "08" => "Aug", "09" => "Sep", "10" => "Oct ", "11" => "Nov", "12" => "dec",); $ MON = $ hash {$ month}; open $ file, "<$ Arg" | die "can not open the log file \ N $! "; While (<$ File>) {chomp; my (UNDEF, UNDEF, $ time, UNDEF, UNDEF, $ method, $ URL, UNDEF) = Split/\ s +/; # print "$ time, $ method, $ URL \ n"; if ($ time = ~ M/$ day \/$ mon \/$ year :( ..)/) {$ hour = $1; if ($ method = ~ /Get/& $ url = ~ /^ \/P \ //) {$ amount ++; $ part {$ hour }+;}} printf ("total amount is % d \ n ", $ amount); = podwhile ($ key, $ value) = each % part) {printf ("The amount of % SH is % d \ n", $ key, $ value) ;}= cutfor $ key (sort keys % part) {printf ("The amount of % SH is % d \ n", $ key, $ part {$ key });}