Re I have several global variables that I pass back and forth between the sub's. ... the sub would modify the global var and the other subs could read it just fine
What do you mean by "pass back and forth" there? If each sub just accessed the global, you're not passing anything. If you are "passing" something too, maybe you're getting something mixed up.
You need to post an example of what you are doing. If that is indeed odd, we'll be able to tell.
Oh, and make sure you use strict and use warnings.
—John | [reply] [d/l] [select] |
Ah the simple answer is usually the best answer. I forgot I had turned of use strict a while back and not turned it back on. Once I fixed the 30+ errors it pointed out. I looked closer and found the following newb error:
print "CCL:08::MyServers = @MyServers\n";
if(undef @MyServers){ &ChooseLocation; }
print "CCL:09::MyServers = @MyServers\n";
The print statements were simply to point out that I did not understand the correct use for undef, as an action and not as a test, or my syntax is wrong for it. I changed it to the following:
unless(@MyServers){ &ChooseLocation; }
Thanks for pointing me back to the basics, it is usually that anyway. =-D
| [reply] |
Dear Initiate,
I'm glad we've been of help, and so quickly, with your first foray into the Monastery.
In your posts, you should look at the available markup. I know you already figured out to use explicit paragraph markers, which is something that often trips up first-timers. The next thing to know is the <code> tag, around your code items and preformatted listings.
You can always go back and edit your post. So you could, if you wanted to practice at it, insert the code tags and fix your typo (missing 'f').
Yes, undef is an action, not a test. The test is defined. So you could write unless (defined $A) {...}
Your final line could also be written the other way around:
&ChooseLocation unless @MyServers;
which has its advantages. Besides the lack of braces and parens, think about how it flows linguistically, once you get used to the idea. You see the action up front. The rest of it, "oh, skip that step if it's not applicable" is off to the side, not the main part of the statement. The core logic reads cleaner.
Also, know that you are testing for an empty array, not defined-ness. I'm pretty sure that a named array variable can't test as undef itself. It can hold any number of elements, some of which may be undef. But itself is empty, still existing as a container.
Oddly enough the documentation (undef) shows an example of undef'ing an array, but doesn't say what it means. Meanwhile testing for definedness on arrays doesn't work, and used to mean something a bit different.
—John
| [reply] [d/l] [select] |