I am trying to read in a 2 column data file into Perl Hash array index. Here is my code.
#!/usr/bin/perl -w
use strict;
use warnings;
my $file = "file_a";
my @line = ();
my $index = 0;
my %ind_file = ();
open(FILE, $file) or die($!);
while(<FILE>) {
chomp($_);
if ($_ eq '')
{
print "undefined line \n";
}
else
{
my ($name, $value) = split(' ', $_);
# Put the key => value pair in the hash
$ind_file{$name} = $value;
# print "$name => $value \n";
my ($k, $v) = each %ind_file;
print "$k => $v \n";
}
}
close(FILE);
while ( ($k, $v) = each %ind_file) {
print "Post $k => $v \n";
}
========================================================
I am getting a lot of these..
Use of uninitialized value in concatenation (.) or string at ./print-hash.pl line 49, <FILE> line 2.
at ./print-hash.pl line 49
any ideas.. and finally when I see the post index file, most of the data read into the hash is missing or gone..
----------------------------------------------------------------------
Input data file: file_a
HOSTNAME aria
AVAIL_MEM 21
USED_MEM 11
HOSTNAME borneo
AVAIL_MEM 31
USED_MEM 1
HOSTNAME croc
AVAIL_MEM 11
USED_MEM 21
USER bob
JL/U 2
RUN 3
PEND 4
WAIT 1
USER jill
JL/U 3
RUN 2
PEND 10
WAIT 3
QUEUE short
JOBS 10
PEND 3
RUN 1
QUEUE long
JOBS 2
PEND 10
RUN 2
=====================================
---------- Post updated at 06:23 PM ---------- Previous update was at 05:47 PM ----------
I got around the uninitialized values part, and missing data is, 'cause the primary key for example: HOSTNAME repeats says 20 times, the Index would remember only the last value stored.
I would like a way to store all possible HOSTNAME (20 times) as an KEY INDEX with values. Any ideas of making this possible?