I thought I was loosing my mind. Please read everything.

John SJ Anderson writes:
> > die("***YOU MUST HAVE A DESTINATION ADDRESS/NETWORK address.\n")
> > if (@destinations);
> 
> Don't you mean 'if !@destinations' or 'unless @destinations' here?
> That test is for whether @destinations has any entries.
        You don't know how helpful this was because when I put
unless in there, it still always succeeded so it was time to do
some serious trouble-shooting.
        Right after the line that makes this test, I assign a
count value to a scaler called $destination_count. It should
show 0 but it is always showing 1 even when I enter nothing and
you can not see anything if you look for that 1 lone character
which is defined earlier in the script as my @destinations and
not touched again until this point.

        Well, that was not true. In the manual input routine, I
had a line that took strings from @ARGV and pushed them in to
another list called @tasks. I then pushed $tasks[1] in to
destinations, no questions asked because there is always
supposed to be something there (unless somebody forgets.) If
$tasks[1] was empty, my code did the push anyway. What
harm could it do? We'll catch that it is empty later.
        It did all kinds of harm. It incremented the internal string
or element count of the array which made the not empty test always succeed.
When I changed the line to 

        push( @destinations, $tasks[1] ) if $tasks[1];

the input routine immediately behaved as it is supposed to and
even prompts the caller for the destination address. This is an
absolute example of the old saying, "Never trust input."

        Thanks to everybody who provided helpful suggestions. It
had gotten to the point where I knew I was doing something odd
to this code to cause strange behavior but I had no idea why
nothing was coming out the way everyone else said it should. It
just wasn't. If I ever teach anyone to program in perl, this
would be a perfect obfuscation exercise. I feel kind of stupid
for wasting everybody's time, but I learned so much that I hope
you forgive me later.

Martin McCormick

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to