in reply to Re: Re: Missing the if statement and going directly to else
in thread Missing the if statement and going directly to else

Your program is doing exactly what you tell it to do. It reads the first line of input from the file, and if it doesn't match, the program exits. That's obviously not what you want it to do, so do something else. Don't exit until either there is a match or you've read the entire file.

Also, you use lexical 'my' variables in one place and package '$main::' package variables in another for no good reason. 'use strict' is a good habit to get into when you're just learning, and if you want globals, put them in a 'use vars' at the top of the script. It'll catch typos in variable names and can save lots of debugging time, and save you from typing 'main::' on all the variables (since 'use vars' declares them in the current package, you don't have to specify the package). If you think this script is too short to bother with 'use strict', then there's no point in the 'my' and 'main::' either.

  • Comment on Re: Re: Re: Missing the if statement and going directly to else

Replies are listed 'Best First'.
Re: Re: Re: Re: Missing the if statement and going directly to else
by Bismark (Scribe) on Jan 17, 2003 at 02:09 UTC
    I do "use strict;" also "use diagnostics -verbose;" I just did not add them to the code I pasted in my scratchpad. I am still trying to grasp the concept of how variables are declared and how they are used. As I said, I have only been using Perl for 1 1/2 weeks. That is how long I have had the Lama and the Camel and I only discovered the Monastery about a week ago.
      I am still trying to grasp the concept of how variables are declared and how they are used.

      Read Dominus's Coping with Scoping (Sorry, I should have mentioned that the first time around).