On 04 May 2012 09:28:45 +0300, Gaal Yahas wrote:
> 
> On Thu, May 3, 2012 at 9:02 PM, Mikhael Goikhman <[email protected]> wrote:
> > 
> > Here is a useful line-based calculator:
> >
> >  perl -ple '$_=eval'
> 
> I prefer
> 
>   perl -de1
> 
> You have to explicitly prefix the expressions whose results you
> want to print with "p" or "x", but in return you get way more
> power. And it's shorter :-)

Ok, but the invocation shortness is less relevant IMO, since you may
alias it. What is more important is the short/convenient usage.

I have this shell alias for years (you are welcome to golf it):

  alias calc='perl -nle "BEGIN
    { if (@ARGV) { print eval qq{@ARGV}; exit } } print eval"'

Then you may conveniently use it interactively, with params and piped:

  calc
  calc 5+37
  calc 1 / 3
  echo '2**15' | calc

Regards,
Mikhael.

-- 
perl -le'print$,.=chr(64+hex),-8x(16+$;--)for+split//,d9b815c07f9b8d1e0'
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to