Ninke has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
once again seeking for your help. I have a file 'param' with '$count $word' on each line and a file 'sent' with some text, each word on each line
I need to tag each word in the 'sent' file with the corresponding count value from the 'param' file:------param------- 200 dog 300 cat 100 rat 400 hen -----sent-------- The cat catches the hen ...
And my code is:The cat 300 catches the hen 400 ...
I believe there is some silly mistake over there, but I can't find it. I will very appreciate your help:)#!/usr/bin/perl use strict; use utf8; use warnings; open PARAM, "param" or die $!; open DEV, "sent" or die $!; my %counts; my @dev; while(<DEV>){ chomp; @dev = <DEV>; } while(<PARAM>) { chomp; my($count, $word) = split / /; $counts{$word} = $count; } foreach my$word_dev(@dev){ if(exists $counts{$word_dev}){ print "$word_dev $counts{$word_dev}\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: hash keys from another file
by moritz (Cardinal) on Mar 23, 2013 at 12:33 UTC | |
by Ninke (Novice) on Mar 23, 2013 at 13:03 UTC | |
by Laurent_R (Canon) on Mar 23, 2013 at 22:43 UTC | |
Re: hash keys from another file
by choroba (Cardinal) on Mar 23, 2013 at 12:31 UTC |
Back to
Seekers of Perl Wisdom