in reply to Finding problem with finding keywords in arrays / files

Are you trying to confuse yourself?
open(INPUT, "data.txt") || die "Error opening 'keywd.txt'\n"; ^^^^----------- wtf? -------------^^^^^

Same here. You use 3 argument open here, you should do the same in the previous open, just to be consistent:

open(FH, '<', "keywd.txt") || die "Error opening 'data.txt'\n";
but you'd better write it like with $!
open(FH, '<', "keyword.txt") || die "Error opening 'keyword.txt': $!\n +"; ^^-- sic! error message in here -----------^^

to get the error (No such file, permission denied, ...) along.

You can chomp an entire array

chomp(my @data = <INPUT>);
and avoid the chomp($element) further down.

And you do a chomp on $element, but not on the contents of the @keywd array. So, your $element never matches e.g. analysis\n. <update> You require there be a newline in $element - but there isn't one, 'twas chomped off. </update>The other way round there would have been a match.

BTW, your code formatting is pretty messy..

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Finding problem with finding keywords in arrays / files
by akirostar (Novice) on Sep 17, 2006 at 13:31 UTC
    thx shmem, as i still new to perl, still trying to grasp the idea. As I had extracted this part of the problem frm the bigger program I m doing. Any chance you know of any idea to form vectors using perl? I am trying to do a program where I could be reading from various files to form vectors from these files after it is compared with a master keyword vector. thanks once again.

      I do... but that really depends on what you mean by Vector ;-)

      Since you are working with words, I guess you are trying to put up a search engine. This article might be a good starter. You might want to have a look at Plucene as well.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}