Below I am trying to read data from a file and trying to store them in an array. The array size in this case should be 6 as highest value of round is 6 (1,2,3,4,5,6).
I am expecting an array of 6 elements having some number. Please help me where I am going wrong. I am new to perl.
if ( !defined($ARGV[0]) ) { print "ENTER OUTPUT Filename\n"; exit 1; }
$outputFile = $ARGV[0];
open(HND, "$outputFile");
while (<HND>)
{
chomp;
my $line = $_;
if ( /Node (.*) sending (.*) data to BS at time (.*) node 0 round (.*)$/ )
{
my $round = $4;
my $data = $2;
if ( exists($CHenergy{$round}) )
{
$CHenergy{$round} += $data;
}
else
{
$CHenergy{$round} = $data;
}
}
}
close HND;
print join(", ", $CHenergy);
At then end I am printing values of the array but it is printing nothing.
use strict; use warnings;at the begining of your scripts.