On Thursday, May 29, 2003, at 13:36 US/Pacific, Bob Showalter wrote:

But the OP was using:

if ($titlelink ne undef)

So,

if (defined $titlelink)

would seem to be equivalent to what he was testing, unless I have it
backwards. Using unless would reverse the sense of the test.

Oh do I feel silly....


Let me try my argument AFTER I have had a cup of coffee....

You are so correct as to what the OP had said,
and hence the more 'direct' pattern. But I think the problem
that the OP is dealing with would 'flow better'
were they to use the form

        unless ( defined $titlelink )
        {
                # do the initializing of $titlelink here
        }

# now one knows that $titlelink IS defined one way or the other

From a programatic approach, i think using an unless block
to make sure that things are initialized actually works better
in the flow of what the OP 'means' to be doing. We of course
will have to leave it up to the OP. But the full alternative
would need to look like:

        if (defined $titlelink) {
LABEL_T_HOP_TO:
                # we have a defined $titlelink we want to work with

        } else {
                # the $titlelink was not defined, so initialize it
                # and hop back up to the side where we ant to do something
                # with an initialized $titlelink

                goto LABEL_T_HOP_TO;
        }

        # now one has an initialized $titlelink AND done the right
        # thing with it....

But as you will agree that
means the goto to hop back into the block above, to do what
ever needs to be done with a defined $titlelink... Or worse
yet, we do not have the else Block, and wind up wandering
around without the $titlelink resolved.

Given that the user was concerned about the error message
that they were playing with an undefined value, the problem
really requires that there be code to actually CORRECT
that case. In the above illustration the 'else block'.

Which of course is why I opted for the 'unless()' approach
of making sure that we had a defined value before we trucked along.

Sorry if I was less clear in my previous post...

ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to