I am trying to read in a 2 column data file into Perl Hash array index. Here is my code.
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
Code:
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?
Last edited by pludi; 10-30-2009 at 04:44 AM..
Reason: code tags, please...
Hi all,
I have written a perl code and stored the data into Data structure using Data::Dumper module.
But not sure how to retreive the data from the Data::Dumper.
Eg.
Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Hi,
I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all .
my %result (
$abc => {
'data_count' => '10',
'ID' => 'ABC122',
}
$def => {
'data_count' => '20',
'ID' => 'defASe',
... (1 Reply)
I have a file containing data like so:
2012-01-02 GREEN 4
2012-01-02 GREEN 6
2012-01-02 GREEN 7
2012-01-02 BLUE 4
2012-01-02 BLUE 3
2012-01-02 GREEN 4
2012-01-02 RED 4
2012-01-02 RED 8
2012-01-02 GREEN 4
2012-01-02 YELLOW 5
2012-01-02 YELLOW 2
I can't always predict what the... (4 Replies)
Hi,
i need a perl script which reads the file, content is given below. and output in new file.
TARGET DRIVE IO1 IO2 IO3 IO4 IO5
------------ --------- --------- --------- --------- ---------
0a.1.8 266 236 ... (3 Replies)
Hi Everyone!
I have a problem in reading a specific column from .xls file using perl language and then manipulating on given criteria.
Detailed Description of the problem::
I have one .xls file, in which i have to populate two columns based on Period_date column which is in same file.
My... (1 Reply)
Hi,
I have a datahash with 'n' number of values in perl script. I am writing a xml file from the datahash. I am getting output with sorting(Field sorting). My question is that i don't want any default sorting.whatever i am inserting into datahash it should give same xml file.
Any help?
... (0 Replies)
Hi, I am writting some perl scripts for daily backup process. In which I want to pass some data/referance from another txt file. Text file contains only one column and multiple rows. I want to pass this data to variables of another perl script.
e.g.
Refdoc.txt file contains data as:
perl1... (3 Replies)
Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below.
#!/usr/bin/perl
use warnings;
use Tie::IxHash;
use strict;
tie (my %programs, "Tie::IxHash");
while (my $line = <DATA>) {
chomp $line;
my(... (1 Reply)
Hello,
I have parsed an xml file using perl to get the hash values and the output looks like this
$VAR1 = {
'RT' => {
'List' => {
'String' => ... (1 Reply)
Experts I am new to UNIX shell programming ( or scripting). My problem is that
I have an ASCII file in which column wise data is present, the columns are seperated by spaces. I want to read each columns data and store it in arrays, next I will be using the arrays to perform some numerical... (1 Reply)