Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Perl Format the Output in table

by protist (Monk)
on Oct 11, 2012 at 15:30 UTC ( #998478=note: print w/ replies, xml ) Need Help??


in reply to Perl Format the Output in table

#!/usr/bin/perl use warnings; use strict; open my $fh, "<", "output.txt" or die "could not open output.txt\n"; my %data; while(<$fh>){ chomp; $_=~ m/(.*?)\s++(\d++)/; my $site=$1; my $week=$2; $data{$site}{$week}++; } print "Domain/WeekNumber\tWeek28\tWeek29\tWeek30\tWeek31\n"; for my $site(sort keys %data){ print"$site\t\t"; for my $week (qw(28 29 30 31)){ unless(defined $data{$site}{$week} ){ print"NO\t"; }else{ print $data{$site}{$week} ."\t"; } } print"\n"; } close $fh;


Comment on Re: Perl Format the Output in table
Download Code
Re^2: Perl Format the Output in table
by Kenosis (Priest) on Oct 11, 2012 at 17:51 UTC

    Nice work on processing the Output.txt file. However, if I'm understanding the OP correctly, the contents of domain.txt are used to filter the contents of Output.txt, such that expand.com will not appear in the final output when using the OP's shown data sets. Given this, perhaps something like the following additions are needed:

    ... open my $fh2, '<', 'domains.txt' or die "could not open domains.txt: $ +!\n"; my %domains = map { chomp; $_ => 1 } <$fh2>; close $fh2; open my $fh, "<", "output.txt" or die "could not open output.txt: $!\n +"; my %data; while (<$fh>) { chomp; $_ =~ m/(.*?)\s++(\d++)/; next unless $domains{$1}; ...
Re^2: Perl Format the Output in table
by ppnair (Initiate) on Oct 12, 2012 at 06:59 UTC

    Thank you very much for the help.

    But 'Output.txt'have got dynamic data.The week Number Will keep on change when ever i pull data from Maillog for current month.

    print "Domain/WeekNumber\tWeek28\tWeek29\tWeek30\tWeek31\n"; and for my $week (qw(28 29 30 31)) will not work for me since the week number chnages every month.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998478]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-10-25 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (140 votes), past polls