no feature qw( indirect );
The following has the same effect:
use v5.36;
use v5.38;
| [reply] [d/l] [select] |
> Add the following to get the desired behaviour:
> no feature qw( indirect );
For completeness, he still needs to predeclare the sub palt .
Either by putting sub palt { ... } earlier or use subs qw(palt); to tell the compiler that it's not a bareword.
Otherwise he'll get
Bareword found where operator expected (Do you need to predeclare "palt"?
| [reply] [d/l] [select] |
| [reply] [d/l] [select] |
no feature qw( indirect );
Cool ... thanks ikegami++
Cheers, Rob
| [reply] [d/l] |
palt 'Math::BigInt'->new(123456);
palt +Math::BigInt->new(123456);
Update: so long as I define (or pre-declare) sub palt before making these calls.
Is there some technique that will allow me to make that (failing) call work - without having to place that argument in brackets ?
Curious to know why you need to do that - XY Problem?
| [reply] [d/l] [select] |
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
| [reply] [d/l] [select] |
use strict;
use warnings;
use palt; # <- new module/pragma
print "This is a palt style print\n";
Is that possible?
Can pragmas be written or are they part of the Perl release? | [reply] [d/l] [select] |