Didn't quite retire the idea, eh? :-)
#!perl -lp
sub _{bless\"@_"}use overload'""',sub{${$_[0]}},neg,sub{_"-$_[0]"},nomethod,sub{_"@_[0,1,3]"};s/-/ -/g;s/\d+/ _('$&')/g;$_=eval
|
Sorry for so many posts in one day. I think it is time to retire this idea.
#!perl -l
sub n{bless\"@_"}use overload'""',sub{${$_[0]}},neg,sub{n"-$_[0]"},nomethod,sub{n"@_[0,1,3]"};$_=<>;s/(-?)[0 ]*(\d+)/ $1 n($2)/g;print eval
|
doesnt pass any tests ..
#!perl -l
sub n{bless\shift}use overload'""',sub{${$_[0]}},'neg',sub{n "-$_[0]"},'nomethod',sub{n "@_[0,1,3]"};$_=
|
There is a perl bug here. bless shift workds on Windows 5.6.1 but not on redhat 5.6.0
#!perl -l
sub n{my$c=shift;bless\$c}use overload'""',sub{${$_[0]}},'neg',sub{n "-$_[0]"},'nomethod',sub{n "@_[0,1,3]"};$_=
|
This doesn't seem to produce any output besides a newline for any input.
#!perl -l package A; $_= |
#!perl -l
package A;
use overload
'""'=>sub{${$_[0]}},
'neg'=>sub{n A "-$_[0]"},
'nomethod'=>sub{n A "@_[0,1,3]"};
sub n{my $c=$_[1];bless \$c}
$_=
|