http://www.perlmonks.org?node_id=1013578


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

Replies are listed 'Best First'.
Re^3: Two simple code style advice questions
by choroba (Cardinal) 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