plennon
asked on
hash tables (cgi)
I have a .dat file which contains many line of data
i have split the line up using split() and i am wanting to read line[5] which contains a name and line[1] which contains it's value.
i want to read them into a hash table, then output them to file
how do i store the 2 values into a hash table and output them to a file in the following format
name, value
name, value
name, value
the file is then read and displayed as a web page
I know very little about hash tables so any feedback will be appreciated
i have split the line up using split() and i am wanting to read line[5] which contains a name and line[1] which contains it's value.
i want to read them into a hash table, then output them to file
how do i store the 2 values into a hash table and output them to a file in the following format
name, value
name, value
name, value
the file is then read and displayed as a web page
I know very little about hash tables so any feedback will be appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my $webfile="file.web";
open DATFILE,"<$datfile" or die "can't open $datfile because $!";
while( <DATFILE> ){
my ($name,$value) = (split)[5,1];
$hash{$name} = $value;
}
close DATFILE;
open OUTPUT,">$webfile" or die "Can't open $webfile because $!";
for( sort keys %hash ){
print OUTPUT "$_,$hash{$_}<br>\n";
}
close OUTPUT;