Path: utzoo!utgpu!watserv1!watmath!att!rutgers!usc!bbn.com!orc!inews!iwarp.intel.com!psueea!parsely!agora!markb From: markb@agora.uucp (Mark Biggar) Newsgroups: comp.lang.perl Subject: Perl as a pocket calculator Message-ID: <1990Jul15.210705.11140@agora.uucp> Date: 15 Jul 90 21:07:05 GMT Reply-To: markb@.UUCP (Mark Biggar) Organization: Betazoid Central Lines: 18 Needing a calculator program the other day and not having anything like bc available, I wrote a simple 6 line perl script that evaled and printed each of its input lines. After playing with it for a while, I noticed that it all could be done very simply from the command line like so: perl -pe "s/^.*$/eval $&/e;" After I mentioned this to Larry he suggested using: perl -pe "s/^.*$/(eval $&).$@/e;" so any error messages would be printed out. This is very useful not only as a pocket calculator replacement, but as a tool for trying perl stuff out when writing perl scripts. -- Perl's Maternal Uncle Mark Biggar