in reply to Looking for pointers or optimizations.

Does the script work? I doubt it. You open the file for writing, not reading. Also, you are getting the number of arguments instead of the file name into $words_file. Oh, that explains why it works. Look for an empty file named 1.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re: Looking for pointers or optimizations.

Replies are listed 'Best First'.
Re^2: Looking for pointers or optimizations.
by thmsdrew (Scribe) on Aug 21, 2012 at 13:56 UTC

    It worked fine but yes there was an empty file named 1.

    If I change it to the following it should work as I meant it to:

    open (my $fh, "<", $ARGV[0]) or die "Can't open input file!"; my @words; while (<>) { push(@words, $_); }
      Better, but not yet correct: you should tell Perl which file handle to read from:
      while (<$fh>) {
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      open (my $fh, "<", $ARGV[0]) or die "Can't open input file!"; my @words; ### The above die function should also return OS_ERROR if open funct +ion failed ### ... die "can't open file: $!"; while (<>) { ### <> will read from the STDIN not the filehandler $fh ### so that should be while(<$fh>){...} push(@words, $_); }

        So if I put in while (<$fh>) it breaks my my $guess = <> further down in my code. I made that my $guess = <STDIN> and it works fine.