Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Looking for pointers or optimizations.

by choroba (Canon)
on Aug 21, 2012 at 13:48 UTC ( #988734=note: print w/ replies, xml ) Need Help??


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.
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988734]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2015-07-02 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (27 votes), past polls