Hello - This is my first perl scripting try.
I am trying to read a file into a hash so i can track it by id
the file looks like this:
ID FILNAME SIZE
1 logfilename 346202741018308
2 logfilename 0261512802421464
3 logfilename 612262297692848
4 logfilename 3268022049187
5 logfilename 888755246426701
6 logfilename 378923465017564
7 logfilename 314595896654591
8 logfilename 827978858998073
9 logfilename 943690319071184
open(FILE, "/tmp/file.txt") or die("Unable to open file");
my %hash;
while (my $line=<FILE>){
chomp($line);
my ($id, $filename, $size) = split/\s+/, $line;
$hash{$id}{filename}= $filename;
$hash{$id}{size}= $size;
}
print "$hash{id}\n\n";
close(FILE); I guess I want my hash to look like this:
%hash_id {
id => $id,
name => $name,
size => $size,
}; I want the first be sure I have $ID has the key for each record
because there can actually be many files for each record.
I want to swap the filename field and the checksum field.
Later in the prog I plan to compare each id records checksum value
when i copy the files. my problem for the moment is simply
getting the records out of the file and into the hash (or array).
I made several attempts and read some threads here but still no luck.