in reply to Re^2: Validating Regular Expression
in thread Validating Regular Expression

It only needs to be converted to a boolean first if it is used in a list assignment. Any usage of the sub in scalar context will behave as expected and as the original spec. We are both making assumptions about how "[o]ne would use the result", and any conclusions are subjective and academic.

Replies are listed 'Best First'.
Re^4: Validating Regular Expression
by ikegami (Patriarch) on Feb 15, 2011 at 18:15 UTC

    We are both making assumptions about how "[o]ne would use the result",

    Not at all. I'm saying you shouldn't introduce bugs in the design of a function based on the assumption that someone might misuse it.

    If you can handle cases of misuse without compromising the design, that's great, but that's not possible here.

    Any usage of the sub in scalar context will behave as expected

    Correct. «return ();» in scalar context functions identically to «return undef;». That makes the behaviour in list context the deciding factor.

    It only needs to be converted to a boolean first if it is used in a list assignment.

    No. Here's an example without an assignment:

    { foo => validate($foo), bar => validate($bar) }

    When using «return ();», the result needs to be converted to a boolean whenever validate is called in list context. That makes no sense for a function that's suppose to return a boolean.