Hello,
what I meant was that this bit of code in the
program(in the subroutine process)
foreach $key(keys %tagcorpus){
print "\n$key";
return($key);
}
gives this as output(the same word as a key):
else
else
else
else
else
else
else
else
else
else
else
else
else
else
whereas this bit of code
while ( ($k,$v) = each %tagcorpus ) {
print "$k => $v\n";
}
prints the key&value pairs properly
else => 1
on => 1
earth => 1
Here => 1
me => 1
am => 1
rather => 1
this => 1
Theres => 1
Id => 1
I => 1
is => 1
nowhere => 1
be => 1
but the subroutine process keeps returning only this word:
else
Thanks for the help on hashes anyway.
I have changed the code and it now works.
Here is the changed file write portion:
open CF, '+<c.txt' or die $!;
seek CF, 0, 0; # go to start of file
truncate CF, 0;
foreach $citem(keys %tagcorpus){
#print "\n$citem";
print CF $citem;
print CF " ";
foreach $ditem(keys %tagdict){
my $currentposition=tell CF;
seek CF,0,1 ;
if ($citem eq $ditem){
print CF "$tagdict{$ditem}";
}
}
}
close CF;
This changes c.txt into(gramm. category against matched
word)
else on earth Here noun me am verb rather this Theres advb Id I is now
+here be
i.e noun against Here
verb against am
advb against Id
Of course the words in the sentence are not properly
ordered.For this I think we need to extract the keys of
%tagcorpus in the insertion order and then write onto the
file.This is what I need to do now :)
Thanx.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.