D
darthbob88
Nub: I'm trying to write a script which will take command line
arguments, x <enter> y <enter> ctrl-D/Z style, and pass them through a
formula, then print the results on separate lines with a bit of fluff
for clarity's sake. I can do it with single arguments and a foreach
loop, but not a group of arguments at once. The code appears below.
I'm trying to write a fairly simple script for use in chemistry and
math-centered classes. Idea is that I pass the script a few arguments,
like
chem 410.1 434.1 [...]
and it passes those through a formula to print out
the numbers associated with x is y.
[ditto z and a]
I can make it work beautifully with one argument, and I can get it to
work equally well if I pass it the numbers using a foreach loop. Yes,
I'm hipped about that. However I cannot get it to work with several
arguments. Here's the entire code, all 9 lines of it.
#!/usr/bin/perl -w
#script to calculate various tedious formulae quickly and save time for
people
$planck = 6.626e-34
$speed_of_light = 2.998e8
#assigns the constants h and c
print "What is the wavelength?\n";
chomp($wavelength = <STDIN>);
#performs calculations E=hc/lambda and prints it
$energy = $planck * $speed_of_light / ($wavelength * 1e-9);
print "The energy associated with wavelength $wavelength nm is $energy
J.\n";
arguments, x <enter> y <enter> ctrl-D/Z style, and pass them through a
formula, then print the results on separate lines with a bit of fluff
for clarity's sake. I can do it with single arguments and a foreach
loop, but not a group of arguments at once. The code appears below.
I'm trying to write a fairly simple script for use in chemistry and
math-centered classes. Idea is that I pass the script a few arguments,
like
chem 410.1 434.1 [...]
and it passes those through a formula to print out
the numbers associated with x is y.
[ditto z and a]
I can make it work beautifully with one argument, and I can get it to
work equally well if I pass it the numbers using a foreach loop. Yes,
I'm hipped about that. However I cannot get it to work with several
arguments. Here's the entire code, all 9 lines of it.
#!/usr/bin/perl -w
#script to calculate various tedious formulae quickly and save time for
people
$planck = 6.626e-34
$speed_of_light = 2.998e8
#assigns the constants h and c
print "What is the wavelength?\n";
chomp($wavelength = <STDIN>);
#performs calculations E=hc/lambda and prints it
$energy = $planck * $speed_of_light / ($wavelength * 1e-9);
print "The energy associated with wavelength $wavelength nm is $energy
J.\n";