Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Two simple code style advice questions

by Anonymous Monk
on Jan 16, 2013 at 14:07 UTC ( #1013578=note: print w/ replies, xml ) Need Help??


in reply to Re: Two simple code style advice questions
in thread Two simple code style advice questions

It strikes me that, as a pattern, 2b works for all values of True, while 2a does not.

What does that mean?

I think they both work for all values of true, even if it isn't clear what you mean by that


Comment on Re^2: Two simple code style advice questions
Re^3: Two simple code style advice questions
by choroba (Abbot) on Jan 16, 2013 at 14:12 UTC
    It probably means "Using '... x condition' is not always safe":
    say $_ ? "true" : "false", "a" x $_ for 0, 1, "0e0";
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Now what do you mean by that? What is it that you expect and how is it unsafe?

        The issue is that the code relies on true being represented by numeric one. While that works for numeric comparisons, it is not a safe assumption in general. So applying this construct to other kinds of tests could be dangerous.

Re^3: Two simple code style advice questions
by Anonymous Monk on Jan 16, 2013 at 18:13 UTC
    While choroba's example is elegantly expresses what I was getting at, I'd also like to point out other True values, like 3, 5 or, more entertainingly, MAXINT. >;^)

      Well, repeat operator repeats a number of times, its repeat operator, if you want to repeat at most once, force !!boolean

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-09-17 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (60 votes), past polls