Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Re: Can you spot the problem?

by TimToady (Parson)
on Mar 05, 2004 at 19:48 UTC ( #334336=note: print w/replies, xml ) Need Help??

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

Works if you change the all the |s to &s. (Plus you can omit the parens if you're golfing, since junctions now bind tighter than comparisons. Well, okay, you can omit the parens even if you're not golfing.)

Replies are listed 'Best First'.
Re: Re: Re: Can you spot the problem?
by ambrus (Abbot) on Mar 05, 2004 at 19:57 UTC

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

      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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://334336]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2017-08-20 02:47 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (313 votes). Check out past polls.