#!/usr/bin/perl use POSIX ; use Term::ReadLine; $init = '#################### numerical constants #################### $pi = 3.14159265358979 ; # pi [ acos(0)*2 ] $e = 2.71828182845905 ; # base of natural logarithm [ exp(1) ] #################### physical constants #################### $h = 6.6260755e-27 ; # Planck constant [erg s] $k = 1.380658e-16 ; # Boltzmann constant [erg/K] $G = 6.67259e-8 ; # gravitational constant [dyne cm^2 g^-2] $c = 2.99792458e10 ; # velocity of light [cm/s] $me = 9.1093897e-28 ; # mass of electron [g] $mp = 1.6726231e-24 ; # mass of proton [g] $mu = 1.6605402e-24 ; # atomic mass unit [g] $Na = 6.0221367e23 ; # [mol^-1] $R = 8.314510e+7 ; # [erg mol^-1 K^-1] $ev = 1.60217733e-12 ; # electron volt [erg] #################### astronomical constants #################### $yr = 3.1556926e7 ; # solar year [s] $au = 1.49597870e13 ; # astronomical unit [cm] $sec= 4.8481368e-06 ; # second [rad] $pc = 3.08e18 ; # persec [cm] 3.08567756705283e18 cm ? $ly = 9.46e17 ; # light year [cm] $rs = 6.96e10 ; # radius of the sun [cm] $ms = 1.9891e33 ; # mass of the sun [g] $ls = 3.85e33 ; # luminosity of the sun [erg/s] $re = 6.378e8 ; # radius of the earth [cm] $me = 5.974e27 ; # mass of the earth [g] # mathematical library functions are included (see also \"man 3 math\") '; print $init; eval $init; if(open(FP,"$ENV{HOME}/.calcrc")){ while(){print; eval $_;} close FP; } $term = new Term::ReadLine 'Simple Perl calc', \*STDIN, \*STDOUT; $prompt = "calc\> "; $OUT = $term->OUT || STDOUT; while ( defined ($_ = $term->readline($prompt, "")) ) { $res = eval($_); warn $@ if $@; print $OUT $res, "\n" unless $@; }