Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Tiny Perl puzzle

by Dominus (Parson)
on Jun 05, 2014 at 21:16 UTC ( #1088921=perlmeditation: print w/replies, xml ) Need Help??

Without testing first, guess what this program will print:
print (two + two == five ? "true" : "false")
Then figure out why you were wrong. (Please mark spoilers accordingly.)

Replies are listed 'Best First'.
Re: Tiny Perl puzzle
by tobyink (Canon) on Jun 05, 2014 at 22:19 UTC

    Good puzzle. This sort of thing is precisely the reason various best practices have arisen.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: Tiny Perl puzzle (duh)
by tye (Sage) on Jun 06, 2014 at 00:22 UTC

    This surprises any even moderately experienced Perl programmer?

    Update: It appears that my test didn't sufficiently accurately replicate the original program text. Though I admit this particular quirk didn't and doesn't bother me much as I avoid barewords exactly because they lead to lots of ambiguities.

    - tye        

Re: Tiny Perl puzzle
by LanX (Sage) on Jun 06, 2014 at 00:35 UTC
Re: Tiny Perl puzzle
by sundialsvc4 (Abbot) on Jun 06, 2014 at 12:09 UTC
    print (two + two == five) ? ( user == politician) ? "Re-elect me and I will fix it." : "It's not a bug, it's a feature!" : (user == accountant) ? "What do you -want- the answer to be?" : "Don't worry, sonny, no child will be left behind." ;
      Another incorrect Perl puzzle?

      (hint: print greedily loves brackets! :)

      Cheers Rolf

      (addicted to the Perl Programming Language)

      (Please mark spoilers accordingly.)

      sundialsvc4, why not honor the OPs request and use spoiler tags?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://1088921]
Approved by atcroft
Front-paged by boftx
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2022-01-22 20:58 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.