The code I'm running produces the error message: "Use of uninitialized value in string eq at C:/Dwimperl/perl/site/lib/Mojo/DOM.pm line 226, <$fh> line 1." It repeats this error message many times while the program is running, and then one final error message saying: "Can't use an undefined value as a symbol reference at Six_gramsC.pl line 33." My code doesn't have 226 lines, so I'm not sure what document is being referenced by the first error message. I also believe I've defined the variable $fh. The program is designed to identify all unique ten-word sequences in a batch of text files and does partially work, in that it produces at least some correct output (the "sequence" hash looks mostly, but not quite all, correct). Can you provide any further insights as to what is causing the error message? (/p>
#!/usr/bin/perl use strict ; use warnings ; use Mojo::DOM; my $path = "U:/Perl/risk disclosures"; chdir($path) or die "Cant chdir to $path $!"; # This program counts the total number of unique six-grams in a 10-K a +nd enumerates the frequency of each one. # Starting off computing a simple word count for each word in the 10-K +. my @sequence ; my %sequences ; my $fh ; # Here creating an array of six-grams. my @files = <*.htm>; foreach my $file (@files) { open($fh, $file|) ; while(<$fh>) { my $dom = Mojo::DOM->new(<$fh>); my $text = $dom->all_text(); for (split/\s+/, $text) { push @sequence, $_ ; if (@sequence >=10) { shift @sequence until @sequence ==10 ; ++$sequences{"@sequence"}; } } } } close($fh) ; my @keys = sort { "\L$sequences{$a}" <=> "\L$sequences{$b}" or "\L$a" cmp "\L$b" } keys %sequences ; open(my $fh3, '>', 'report4.txt') ; foreach (@keys) { print $fh3 "$_ \t $sequences{$_}\n "; } close $fh3 ;
In reply to Use of uninitialized value in string eq by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |