in reply to Missing the if statement and going directly to else

In the code you gave, $PartNumber isn't set. Could you give some small, runable program, that "misbehaves", including the data it's misbehaving on. Because without data, and with just an incomplete program, it would be just guessing.

Abigail
-- 
It could be solar flares.

Replies are listed 'Best First'.
Re: Re: Missing the if statement and going directly to else
by Bismark (Scribe) on Jan 17, 2003 at 01:29 UTC
    The entire is actually in my scratchpad
      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.

        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.