each line, and creates a hash with? the first string as key and second string as value.
Below is my code but it is not working when I run it. After running the code is says press any key and continue.
use strict;
use warnings;
my $FILE_PATH="SAMPLE.TXT";
my %hash = get_hash ("$FILE_PATH");
print "\n$_ : $hash{$_}" for (keys %hash);
sub get_hash
{
my ($FILE_NAME)=@_;
my %temp=();
open (FIN, "$FILE_NAME") || die "Cannot open the $FILE_NAME : $!";
$temp{$1}=$2 while (<FIN>=~ m/^(.*)\t+(.*?)$/);
close (FIN);
return %temp;
}
I stated in my earlier post that when I run the script I only get a response saying "Press any key to continue." I am running it like I normally do all of my other perl scripts where the answer comes in a new console.
This is the info in the file:
Cameron name
square shape
dinosaur animal
age 100
Below is my code but it is not working when I run it. After running the code is says press any key and continue.
use strict;
use warnings;
my $FILE_PATH="SAMPLE.TXT";
my %hash = get_hash ("$FILE_PATH");
print "\n$_ : $hash{$_}" for (keys %hash);
sub get_hash
{
my ($FILE_NAME)=@_;
my %temp=();
open (FIN, "$FILE_NAME") || die "Cannot open the $FILE_NAME : $!";
$temp{$1}=$2 while (<FIN>=~ m/^(.*)\t+(.*?)$/);
close (FIN);
return %temp;
}
I stated in my earlier post that when I run the script I only get a response saying "Press any key to continue." I am running it like I normally do all of my other perl scripts where the answer comes in a new console.
This is the info in the file:
Cameron name
square shape
dinosaur animal
age 100