Is there a way to write a perl subroutine that can read in a file that contains 2 strings on each line and then can create a has with the first string as key and second string as value without using the use the Tie::File::AsHash module ?
Makailah
0
Newbie Poster
Recommended Answers
Jump to Postuse strict; use warnings; ### Declare you input file location my $f_path="e:/dani/test1/hash.txt"; ### Declare your Subroutine and the file as a argument my %hash = get_hash ("$f_path"); ### print the input file keys and values print "\n$_ : $hash{$_}" for (keys %hash); sub get_hash { my ($f_name)=@_; …
Jump to PostI assume your file having keys followed by tab dellimiter and values. If your file having another delimiter modify the below regex part as per your input.
while (<FIN>=~ m/^(.*)\t+(.*?)$/
All 6 Replies
k_manimuthu
43
Junior Poster in Training
Makailah
0
Newbie Poster
k_manimuthu
43
Junior Poster in Training
Makailah
0
Newbie Poster
k_manimuthu
43
Junior Poster in Training
yuvanbala
2
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.