Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Command-Line Arguments

Reply
Thread Tools

Command-Line Arguments

 
 
darthbob88@gmail.com
Guest
Posts: n/a
 
      11-13-2005
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";

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-13-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1131847766.746643.174640
@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
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
 
DarthBob88
Guest
Posts: n/a
 
      11-13-2005
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.

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-13-2005
"DarthBob88" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

[ 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:

>> $planck = 6.626e-34
>> $speed_of_light = 2.998e8

>
> 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

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      11-13-2005

"DarthBob88" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.



 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-13-2005
DarthBob88 <(E-Mail Removed)> wrote:

> 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!


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Eric Bohlman
Guest
Posts: n/a
 
      11-13-2005
"DarthBob88" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> 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.
 
Reply With Quote
 
DarthBob88
Guest
Posts: n/a
 
      11-14-2005
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.

 
Reply With Quote
 
DarthBob88
Guest
Posts: n/a
 
      11-14-2005
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.

 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      11-14-2005
DarthBob88 wrote:
> 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/cl...uidelines.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).

--
http://DavidFilmer.com

The best way to get a good answer is to ask a good question.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call again a variadic function (... variable number of arguments)with same arguments that its variadic wrapper moreau.steve@gmail.com C Programming 3 12-31-2008 07:13 AM
how to pass a function name and its arguments inside the arguments of other function? jmborr Python 1 11-03-2007 08:20 AM
function default arguments from other arguments tutmann C++ 4 10-17-2006 08:00 PM
function call with arguments which takes no arguments Neo C Programming 10 01-20-2005 06:31 AM
Difference between default arguments and keyword arguments Edward Diener Python 14 04-05-2004 11:26 PM



Advertisments