Thank you for your help!
I am a beginner for perl, sorry for all my silly mistake!
I need to read in two files, the first part works good.The second part,now I fixed a little bit, and test it, it can give me only one letter of the data, but my data should be the whole sequence, and my hash does not print out anything either. Please help!
#!/usr/bin/perl -w
use strict;
my ($file_list, $file_data)=@ARGV;
my %MYHASH;
#create hash
sub do_hash {
my $filename=shift;
open(FH, $filename) or die "Can't open $filename: $!\n";
while(<FH>){
my ($Name, $Data)=split,1;
while (my ($key, $value)=each (%MYHASH)){
rint $Name,"=>",$Data," ";
}
}
close FH;
}
do_hash('file_data');
exit;
| [reply] [d/l] [select] |
#!/usr/bin/perl -w
use strict;
my ($file_list, $file_data)=@ARGV;
my %MYHASH;
#create hash
sub do_hash {
my $filename=shift;
open(FH, $filename) or die "Can't open $filename: $!\n";
while(<FH>){
my ($Name, $Data)=split,2;
$MYHASH{$Name} = $Data;
}
close FH;
}
do_hash('file_data');
foreach my $key (keys %MYHASH) {
print "$key => $MYHASH{$key}\n";
}
exit;
Note the fact that %MYHASH is assigned a whole bunch 'o data from the file, and after do_hash is completed (and %MYHASH has stuff in it) THEN all the data is printed out. And BTW, it should've probably been split, 2 not split, 1.
Gary Blackburn
Trained Killer | [reply] [d/l] [select] |
Thanks,
You are right, I make it today.
| [reply] |