in reply to problem count the number of words
open (my $inwp , "<:encoding(utf8)" , "$pwt") or die "$pwt: $!" ; while (<$inw>) { my @pwords ; my @ptw ; my $elementp ; my $countp ; @pwords = split (/\n/ , $inwp) ;
The variable $inwp is a FILEHANDLE and does not contain any data from the file $pwt.
open (my $nwt , "<:encoding(utf8)" , "$ntw" ) or die "$ntw: $!" ; while (<$itw>) { $numlinenw++ ; my @nwords ; my @ntw ; my $elementn ; my $countn ; @nwords = split (/\n/ , $nwt) ;
The same thing with the variable $nwt.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem count the number of words
by GHMON (Novice) on Dec 27, 2018 at 17:19 UTC | |
Hi bro i have 2 files that include a lot of sentences and also i have 2 files include negative words and positive words and i want to count the number use of these 2 type of words in the sentences , my sentences are $pt = '/root/Positive.txt' , $nt = '/root/Negative.txt' so my words are $pwt = '/root/Positive2.txt' , $ntw = '/root/Negative2.txt' , now i want to count the number of words in 2 sentences by this code | [reply] |
by AnomalousMonk (Archbishop) on Dec 27, 2018 at 20:16 UTC | |
Here's an example of counting defined sets of "words" (which can be tricky to define) based on the technique described in the Building Regex Alternations Dynamically article by haukex. If you can figure out how to get the contents of your positive and negative word data files into the corresponding arrays (and if my notion of what you want is anywhere near what you actually want), you may be on your way. Note that the code is set up for case-insensitive matching and counting: the negative word "fourscore" matches "FoUrScOrE" in the example sentence, and so on. Note, again, that the concept of a "word" can be slippery, so the use of the \b boundary assertion, among other details, may not be appropriate.
Update: In the make_regex() function, the lines Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
by GHMON (Novice) on Dec 28, 2018 at 09:37 UTC | |
Hi TNX bro i could find the my problem , my problem was about these section *foreach (my $word = <$inwp>) { $countp{$word}++ ; }* , *foreach (my $word = <$nwt>) {$countn{$word}++ ; }* because i split the words by /\n/ that my code didn't need to this separator my new code
| [reply] [d/l] |
by poj (Abbot) on Jan 01, 2019 at 17:06 UTC | |