Command-Line Arguments

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";
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g43g2000cwa.googlegroups.com:
Nub: I'm trying to write a script which will take command line
arguments,

Read about @ARGV in perldoc perlvar
x <enter> y <enter> ctrl-D/Z style,

That's just basic input, has nothing to do with command line arguments.

....
#!/usr/bin/perl -w

use strict;

missing.
$planck = 6.626e-34
$speed_of_light = 2.998e8

Please post real code.

Sinan
 
D

DarthBob88

Thank you for your assistance. I did post the actual code that I am
using, variables comments and everything. Apologies if you did not care
for it.
 
A

A. Sinan Unur

[ Please quote an appropriate amount of context when you reply ]
Thank you for your assistance. I did post the actual code that I am
using, variables comments and everything. Apologies if you did not care
for it.

You snipped the relevant part:
Please post real code.

I don't see any semi-colons.

Please read the posting guidelines for this newsgroup for information on
how to compose a post.

Sinan
 
T

Tintin

DarthBob88 said:
Thank you for your assistance. I did post the actual code that I am
using, variables comments and everything. Apologies if you did not care
for it.

You must have a specially modified version of Perl to run your script. I
(and everyone else) get:

$ perl foo
Scalar found where operator expected at foo line 5, near "$speed_of_light"
(Missing semicolon on previous line?)
syntax error at foo line 5, near "$speed_of_light "
Execution of foo aborted due to compilation errors.
 
T

Tad McClellan

DarthBob88 said:
Thank you for your assistance.


Thank who for what assistance?

Please quote the relevant context in your followups like everybody else does.

I did post the actual code that I am
using,


No you didn't.

If it was your actual code, you would be here asking about the
syntax error that it produces.

If you continue to make false claims about your situation, people
will start ignoring your posts, so you probably shouldn't do that.

Apologies if you did not care
for it.


The perl interpreter did not care for it, therefore it was
not Perl code at all!
 
E

Eric Bohlman

Thank you for your assistance. I did post the actual code that I am
using, variables comments and everything. Apologies if you did not care
for it.

You didn't post your actual code. You attempted to type your code into
your post, and as almost always happens when people do that, the code
mutated. In this particular case, it was fairly easy for a reader to
tell what the two lines that were pointed out to you should have been,
but in the general case, it isn't. Regulars here have learned through
bitter experience that when there's evidence that code has been retyped,
trying to guess what the original was leads to unproductive exchanges and
the only way to solve the problem is to ask the poster to cut-and-paste
the code in question.

There have been at least a few occasions when a poster retyped code and
nobody could find anything wrong with it; the reason was that, due to a
phenomenon called "psychological set" (see Gerald Weinberg's classic _The
Psychology of Computer Programming_), the poster saw, and typed, what he
had meant to write in the first place rather than what he actually did
(anybody who has spent a non-trivial amount of time debugging programs or
proofreading manuscripts will have experienced this; our brains have a
generally-useful ability to correct errors in information delivered by
noisy channels, but it gets in the way when you're actually trying to
measure the noise level). Other times there was a true problem in the
retyped code, but not in the original.
 
D

DarthBob88

When I said, thanks for the assistance, there was only one person for
me to thank, so by the pigeonhole principle that was the person I was
thanking.
As for the missing semi-colons, that's most likely an I-D-10-T error,
caused by blatant and mind-boggling incompetence on my part. I shall
engage in a few hours of self-flagellation to atone for it. I am only
just starting to use Perl, and so I haven't gotten into the
programmer's mindset as yet.
The reason I did not quote anyone here is A) this is a sentiment
expressed by multiple people, I could not direct it to any one person,
and B) I'm leaving the group anyway, until I manage to get over this
blow to my pride.
 
D

DarthBob88

When I said, thanks for the assistance, there was only one person for
me to thank, so by the pigeonhole principle that was the person I was
thanking.
As for the missing semi-colons, that's most likely an I-D-10-T error,
caused by blatant and mind-boggling incompetence on my part. I shall
engage in a few hours of self-flagellation to atone for it. I am only
just starting to use Perl, and so I haven't gotten into the
programmer's mindset as yet.
The reason I did not quote anyone here is A) this is a sentiment
expressed by multiple people, I could not direct it to any one person,
and B) I'm leaving the group anyway, until I manage to get over this
blow to my pride.
 
U

usenet

DarthBob88 said:
When I said, thanks for the assistance, there was only one person for
me to thank, so by the pigeonhole principle that was the person I was
thanking.
As for the missing semi-colons, that's most likely an I-D-10-T error,
caused by blatant and mind-boggling incompetence on my part. I shall
engage in a few hours of self-flagellation to atone for it. I am only
just starting to use Perl, and so I haven't gotten into the
programmer's mindset as yet.
The reason I did not quote anyone here is A) this is a sentiment
expressed by multiple people, I could not direct it to any one person,
and B) I'm leaving the group anyway, until I manage to get over this
blow to my pride.

I see that you have STILL not followed Sinan's kind advice:

Please read the posting guidelines for this newsgroup for
information on how to compose a post.

and he gave you link:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

Your pride will suffer far less (and you would get much more effective
assistance) if you would read and follow these simple guidelines. The
guidelines exist for YOUR benefit (because they show you how to compose
effective posts which are much more likely to get effective responses -
without getting flamed).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top