in reply to Re^2: Global var's that don't hold between subroutines
in thread Global var's that don't hold between subroutines
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:
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.&ChooseLocation unless @MyServers;
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
|
|---|