Hi..
I got an error message as below after execute my program:-
Useless use of private variable in void context at /home/ASUS/bin/burs
+t2arbor.pl line 114.
Useless use of private variable in void context at /home/ASUS/bin/burs
+t2arbor.pl line 131.
Otherwise, I have used function converTime to convert date into unixtime in perl, is it correct ?
This is my program
#!/usr/bin/perl -w
use warnings;
use strict;
use POSIX qw(strftime);
use Getopt::Long;
use Cwd;
use POSIX qw(floor ceil);
use constant BURSTABLE => "BURSTABLE";
use constant BURSTABLE_SELECT => "BURSTABLE_SELECT";
my ($rec, $all, $arborcsv, $arbor, $indir, $outdir, $arcdir, $fname);
my ($dur, $recType, $rec_size, $num_record, $application, $version, $d
+ata_record, $default);
my $creation_dt = strftime "%Y%m%d%H%M%S", localtime;
my $fix = "100";
my $fix2 = "1";
GetOptions (
"all" => \$all,
"arborcsv" => \$arborcsv,
"arbor" => \$arbor,
"i=s" => \$indir,
"o=s" => \$outdir,
"a=s" => \$arcdir,
"f=s" => \$fname,
) or usage();
my @hdrsize = (3, 14, 4, 7, 16, 5, 12);
my @trlsize = (6, 28, 8, 14, 32, 10, 24);
my @min_burstable = ();
my @max_burstable = ();
my @tiu_burstable = ();
my @min_burstable_select = ();
my @max_burstable_select = ();
my @tiu_burstable_select = ();
sub usage {
print "USAGE: $0 -[all|arbor|csv] -f <file name>\n";
}
sub convertTime {
#expects time in yyyy-mm-dd hh:mm:ss format
my( $time ) = shift;
my( $year, $month, $day, $hour, $minute, $sec ) = $time =~ /(\d+)-
+(\d+)-(\d+) (\d+):(\d+):(\d+)/;
my $oneday = 24 * 3600; #for convenience
my $utime = $sec + ($minute * 60) + ($hour * 3600); ## time in sec
+onds on the day in question
$year -= 1970;
my @months = (31,28,31,30,31,30,31,31,30,31,30,31);
for (my $i=0; $i < ($month-1); $i++ ) {
$utime += ($months[$i] * $oneday);
}
$utime += ((($year - ($year%4))/4) * $oneday); ## take leap years
+into account
if( ($year%4)==0 && $month < 3 ) { $utime -= $oneday; }
$utime += (($day-1) * $oneday);
$utime += ($year * 365 * $oneday);
$utime -= 8*3600; # TimeZone for Malaysia
return $utime;
}
sub inttohex {
my $int = shift;
return sprintf ("%02X", $int);
}
sub read_burstable {
my ($data, $min, $max, $tiu);
my $num = 0;
open (DATA, "/home/ASUS/burstable_select.tab");
while ($data = <DATA>) {
chomp($data);
next if $data =~ /^#/;
($tiu, $min, $max) = split(/\s/,$data);
$min_burstable_select[$num] = $min;
$max_burstable_select[$num] = $max;
$tiu_burstable_select[$num] = $tiu;
$num++;
}
close(DATA);
$num = 0;
open (DATA, "/home/ASUS/burstable.tab");
while ($data = <DATA>) {
chomp($data);
next if $data =~ /^#/;
($tiu, $min, $max) = split(/\s/,$data);
$min_burstable[$num] = $min;
$max_burstable[$num] = $max;
$tiu_burstable[$num] = $tiu;
$num++;
}
close(DATA);
}
sub get_burstable_tiu {
my $tiu = shift;
my ($min, $max, $tec);
my $i = 0;
for $min (@min_burstable) {
$max = $max_burstable[$i];
if ($tiu => $min && $tiu < $max) {
$tec = $tiu_burstable[$i];
last;
}
$i++;
}
return $tec;
}
sub get_burstable_select_tiu {
my $tiu = shift;
my ($min, $max, $tec);
my $i = 0;
for $min (@min_burstable_select) {
$max = $max_burstable_select[$i];
if ($tiu => $min && $tiu < $max) {
$tec = $tiu_burstable_select[$i];
last;
}
$i++;
}
return $tec;
}
sub create_header {
if ($arborcsv || $all) {
$recType = "HDR";
$creation_dt = strftime "%Y%m%d%H%M%S", localtime;
$rec_size = "0000";
$num_record = "0000000";
$application = "NV2:MCS R3.0";
$version = "01.00";
$data_record = "TE2";
printf (CSV "%s,%s,%s,%s,%s,%s,%s,%s,%s\n", $recType, $creatio
+n_dt, $rec_size, $num_record, $application, $version, $data_record, "
+ ", " ");
} elsif ($arbor || $all) {
$recType = sprintf("%3s","HDR");
$creation_dt = sprintf ("%14s", strftime "%Y%m%d%H%M%S", local
+time);
$rec_size = sprintf ("%s","0000");
$num_record = sprintf ("%s", "0000000");
$version = sprintf ("%5s", "01.00");
$data_record = sprintf ("%3s", "TE2");
$default = sprintf ("%12s", " ");
printf (DAT pack 'A3 A14 A4 A7 A16 A5 A3 A12 h1', $recType,$cr
+eation_dt,$rec_size,$num_record,"NV2:MCS R3.0",$version,$data_record,
+$default,"A");
}
}
sub create_data {
my ($usage_cnt, $burst, $usage_final, $tiu);
my ($yy, $mm, $dd, $HH, $MI, $SS, $new_dt, $unix_dt);
$rec = 0;
open (DATA, "$indir/$fname");
while (my $data = <DATA>) {
chomp($data);
my ($insert_date,$id,$service_id,$start_date,$end_date,$usage_
+95,$min_cap,$max_cap,$product_name) = split(/;/, $data);
$min_cap = floor($min_cap);
$max_cap = floor($max_cap);
my $burst = ($min_cap > 0) ? BURSTABLE_SELECT : BURSTABLE;
if ($burst eq BURSTABLE) {
$usage_final = ($usage_95 >= $max_cap) ? floor($max_cap) :
+ floor($usage_95);
$tiu = get_burstable_tiu($usage_final);
} else {
if ($usage_95 >= $max_cap) {
$usage_cnt = $max_cap - $min_cap;
} else {
$usage_cnt= $usage_95 - $min_cap;
}
$usage_final = ($usage_cnt > 0) ? $usage_cnt : 0;
$tiu = get_burstable_select_tiu($min_cap);
}
my ($equipment_no,$dt,$point_target,$point_origin,$primary_val
+ue) = ($service_id,$start_date,$min_cap,$service_id,$usage_final);
if ($arbor || $all) {
$dur = sprintf ("%08s", inttohex($usage_final));
($yy, $mm, $dd, $HH, $MI, $SS) = $dt =~ /(\d+)-(\d+)-(\d+)
+ (\d+):(\d+):(\d+)/;
#expects time in yyyy-mm-dd hh:mm:ss format
$new_dt = sprintf("$yy-$mm-$dd $HH:$MI:$SS");
$unix_dt = inttohex(convertTime($new_dt));
print (DAT pack "H*", $tiu);
print (DAT pack "A16", $equipment_no);
print (DAT pack "H*", $unix_dt);
print (DAT pack "A16", $point_target);
print (DAT pack "A16", $equipment_no);
print (DAT pack "H*", $dur);
print (DAT pack "H2", "64");
print (DAT pack "H2", "01");
} elsif ($arborcsv || $all) {
print (CSV "$rec,$tiu,$equipment_no,$dt,$point_target,$equ
+ipment_no,$usage_final,$fix,$fix2\n");
}
$rec++;
}
close(DATA);
}
sub create_trailer {
if ($arborcsv || $all) {
$recType = "TRA";
$rec_size = "0000";
$creation_dt = strftime "%Y%m%d%H%M%S", localtime;
$num_record = sprintf ("%07s",$rec);
$application = "NV2:MCS R3.0";
$version = "01.00";
$data_record = "TE2";
printf (CSV "%s,%s,%s,%s,%s,%s,%s,%s,%s", $recType, $creation_
+dt, $rec_size, $num_record, $application, $version, $data_record, " "
+, " ");
} elsif ($arbor || $all) {
$recType = sprintf("%3s","TRA");
$creation_dt = sprintf ("%14s", strftime "%Y%m%d%H%M%S", local
+time);
$rec_size = sprintf ("%4s","0000");
$num_record = sprintf ("%07s",$rec);
$version = sprintf ("%5s", "01.00");
$data_record = sprintf ("%3s", "TE2");
$default = sprintf ("%12s", " ");
printf (DAT pack 'A3 A14 A4 A7 A16 A5 A3 A12 h1', $recType,$cr
+eation_dt,$rec_size,$num_record,"NV2:MCS R3.0",$version,$data_record,
+$default,"A");
}
}
if (!defined($indir)) {
$indir = getcwd;
}
read_burstable();
if ($arcdir) {
my $fname_arc = $fname . "." . $creation_dt;
system("cp $indir/$fname $arcdir/$fname_arc");
}
if ($arborcsv || $all) {
(my $fname_csv = $fname) =~ s/.csv/.cst/g;
open (CSV, ">$outdir/$fname_csv");
}
if ($arbor || $all) {
(my $fname_dat = $fname) =~ s/.csv//g;
open (DAT, ">$outdir/$fname_dat");
}
create_header();
create_data();
create_trailer();
close(CSV) if ($arborcsv || $all);
close(DAT) if ($arbor || $all);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.