in reply to Re^3: Use of uninitialized value in string eq
in thread Use of uninitialized value in string eq

Good call. I inserted the "or die 'Can't open...$!'" command after the open command to get feedback on the error. Now running the code produces the error message: "Can't use string ("1000694-R201203014-C20111231-F10-"...) as a symbol ref while "strict refs" in use at Six_gramsC.pl line 20. That long numeric string is one of the file names I"m running through the batch (and representative of the other file names). Is there something inherently wrong with this filename, or is the program reading the file name where I'm trying to get it to read the file contents?

  • Comment on Re^4: Use of uninitialized value in string eq

Replies are listed 'Best First'.
Re^5: Use of uninitialized value in string eq
by toolic (Bishop) on Sep 10, 2014 at 16:33 UTC
    open($fh, $file|) ;
    That generates a syntax error for me. Is that your exact code?

      No--it looks like I must have added the | immediately prior to the initial posting. I've taken out the $fh from the code, so it now reads:

      my @files = <*.htm>; foreach $file (@files) { open($file or die "can not open .txt file: $!") ; while(<$file>) { my $dom = Mojo::DOM->new(<$file>); my $text = $dom->all_text(); for (split/\s+/, $text) { push @sequence, $_ ; if (@sequence >=10) { shift @sequence until @sequence ==10 ; ++$sequences{"@sequence"}; } } } } close($file) ;

      This specification is what generates the "Can't use string..." error I cited.

        This won't do what you want, whether it compiles or not.:

          open($file or die "can not open .txt file: $!") ;

        This line appears to have changed from the original node:

        foreach $file (@files) {

        That will not work under strict unless you've added a my $file somewhere above that. Try not to hand-copy the code. Using copy and paste is much more accurate.