Hi Serf, I was trying to add another column which is the last month period in the report output. I was able to get the last month period like 1 Feb 10 - 28 Feb 10. But when I tried to add the column in the program. The new "Period" column is inserted in a diffent row.
Current Ouput with new Period Column:
CUSTOMER NAME: AGD-WEb
Period Device_Code Port Traf_Dir Data_Usage
1Feb2010 - 28Feb2010
SWITCH Fa1_0_33 OUT1.311
1Feb2010 - 28Feb2010
SWITCH Fa1_0_33 IN10.716
1Feb2010 - 28Feb2010
SWITCH Fa1_0_35 OUT50.796
1Feb2010 - 28Feb2010
SWITCH Fa1_0_35 IN7.882
1Feb2010 - 28Feb2010
SWITCH Fa2_0_33 OUT-0.000
1Feb2010 - 28Feb2010
SWITCH Fa2_0_33 IN-0.000
1Feb2010 - 28Feb2010
SWITCH Fa2_0_35 OUT-0.000
1Feb2010 - 28Feb2010
SWITCH Fa2_0_35 IN-0.000
Here's the code I updated with $lastmonth_period (I use DateTime module from CPAN) :) :
for my $customer ( keys %$cust ) {
# If you want to write to a file named with the customer ID
# my $output = "./$customer.out";
# If you want to write to a file named with the customer name
my $output = "./$cust->{$customer}->{name}.txt";
open (CUST_OUT, ">$output") || die "Can't write to '$output': $!\n
+";
print CUST_OUT "Data Transfer Report for $cust->{$customer}->{name
+}\n" .
"Period Device_Code Port T
+raf_Dir Data_Usage\n";
for my $device ( sort by_name keys %{$bill_data->{$customer}} ) {
for my $port ( sort keys %{$bill_data->{$customer}->{$device}}
+ ) {
(my $short_port = $port) =~ s/^FastEthernet/Fa/g;
for my $direction qw(OUT IN) {
print CUST_OUT "$lastmonth_period $device $short_port
+$direction" .
$bill_data ->{$customer}->{$device}->{$port}->{$di
+rection} . $/;
}
}
}
close(CUST_OUT);
}
The output I am trying to do should be like:
CUSTOMER NAME: AGD-WEb
Period Device_Code Port Traf_Dir Data_Usage
1Feb2010 - 28Feb2010
SWITCH Fa1_0_33 OUT1.311
1Feb2010 - 28Feb2010
SWITCH Fa1_0_33 IN10.716
1Feb2010 - 28Feb2010
SWITCH Fa1_0_35 OUT50.796
1Feb2010 - 28Feb2010
SWITCH Fa1_0_35 IN7.882
1Feb2010 - 28Feb2010
SWITCH Fa2_0_33 OUT-0.000
1Feb2010 - 28Feb2010
SWITCH Fa2_0_33 IN-0.000
1Feb2010 - 28Feb2010
SWITCH Fa2_0_35 OUT-0.000
1Feb2010 - 28Feb2010
SWITCH Fa2_0_35 IN-0.000
Also, I need to get the total Data Usage of each customer, so i need to get the sum. Can please help me on this? Or how should I update the code from here? I'm currently lost right now.
Thanks a lot!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.