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

open($fh, $file|) ;
That generates a syntax error for me. Is that your exact code?

Replies are listed 'Best First'.
Re^6: Use of uninitialized value in string eq
by Anonymous Monk on Sep 10, 2014 at 17:00 UTC

    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.

        Why won't that line do what I want? Is there something wrong with the open file statement I'm using? When I try a two-argument open command by assigning $file to a filehandle called INFILE, I get an error message saying: "Useless use of a constant (INFILE) in void context..." In addition, under the copied and pasted code I show in my earlier comment (which does have a 'my $file' at the top not included in the copy and paste), I continue to get an error message saying: "Can't use string ("1000694-R20120314-C20111231-F10-"...) as a symbol ref while "strict refs" is use", referring to the line where my open file command is. This error seems to suggest my code is reading the name of the file as a string instead of the file itself. Any idea how to fix that?