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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.