in reply to Re: Re: Can you spot the problem?
in thread Can you spot the problem?

I'd rather leave the |'s and change the comparison from "if ... <256" to "unless ... >255". That way the puzzle still works in perl5.

Replies are listed 'Best First'.
Re^4: Can you spot the problem?
by Roy Johnson (Monsignor) on Mar 05, 2004 at 21:09 UTC
    I like making it all into one logical return expression, with no conditionals.

    Without the two character fix/spoiler:

    sub isValidIP { return (shift =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ and (($1|$2|$3|$4) + < 256)); }
    Update: I wasn't offering a Perl 6 solution, despite the subthread my response was in. That would be
    return (shift =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ and not (($1|$2|$3 +|$4) > 255));

    The PerlMonk tr/// Advocate