Curious to know why you need to do that

Let's say I don't like the way that perl's print() function outputs non-zero NVs.
So I write an "alt"ernative "p"rint function (palt()) that outputs non-zero NVs as I like to see them presented.

Then, whenever I want to print() a scalar, I need to keep track of whether that scalar is a non-zero NV, or whether it's something else.
If it's a non-zero NV, I certainly don't want to do  print($sv), and if it's a plain string or a reference to a module object, I certainly don't want to coerce it to an NV by doing palt($sv).
It would be much better, IMO, if I could just use palt() every time I wanted to print anything - and rely on it to provide the customized output for non-zero NVs, and also to provide the same output as print for all other arguments.
And that's essentially what I've done.

Given that print is rarely given bracketed arguments, it would be nice if palt did the same.
But if that can't be done, then I just document that palt should always be given bracketed argument(s) ... and move on.
It's not really a big deal ... just something I wanted to check on.

ikegami's solution looks fine to me - the only downside being that it doesn't port back to pre-5.36 perls, IIUC.

Cheers,
Rob

In reply to Re^2: Calling a sub without enclosing its argument inside brackets by syphilis
in thread Calling a sub without enclosing its argument inside brackets by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.