perl -ple'$_=eval'
is a bit easier to use :)
U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk
| [reply] [d/l] |
How would you pass parameters to that expression?
Rich36
There's more than one way to screw it up...
| [reply] |
How would you pass parameters to that expression?
2;130 juerd@ouranos:~$ perl -ple'$_=eval'
1+1
2
3*100
300
U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk
| [reply] [d/l] |
You can make this take a command argument very easily. In fact you can replace the expr function with this:
function calc {
perl -ple '$_=eval'
}
function expr {
echo "$1" | calc
}
Toku | [reply] [d/l] |
perl -le'print eval shift'
Or, to slurp all arguments:
perl -le'print eval "@ARGV"'
U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk
| [reply] [d/l] [select] |
The Perl debugger interface, to me, is too cluttered for this purpose, especially considering the -- what are they, ANSI control codes? -- formatting. Python's interactive mode is somewhat better, but Python doesn't do math quite as well as Perl, I think. Interactive Ruby (irb), out of the three, is IMHO the best; as two examples, Ruby automatically switches to bignums when necessary, and is not as whitespace-dependent as Python (important in interactive mode)... the major disadvantage is that it is much less common than Perl and Python, or so I've seen.
| [reply] |
The Perl debugger interface, to me, is too cluttered for this purpose, especially considering the -- what are they, ANSI control codes? -- formatting.
ANSI codes, yes, because it's using Term::ReadLine::Gnu and Term::ReadLine (on my system at least) - i think they look cool, myself. (:
of course, if you want an interactive calculator, the Term::Readline manual has a nice example.
--
strfry()
| [reply] |