Command-Line Arguments

Discussion in 'Perl Misc' started by darthbob88@gmail.com, Nov 13, 2005.

  1. Guest

    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";
     
    , Nov 13, 2005
    #1
    1. Advertising

  2. 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 <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Nov 13, 2005
    #2
    1. Advertising

  3. DarthBob88 Guest

    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.
     
    DarthBob88, Nov 13, 2005
    #3
  4. "DarthBob88" <> wrote in
    news::

    [ 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 <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Nov 13, 2005
    #4
  5. Tintin Guest

    "DarthBob88" <> wrote in message
    news:...
    > 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.
     
    Tintin, Nov 13, 2005
    #5
  6. DarthBob88 <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 13, 2005
    #6
  7. Eric Bohlman Guest

    "DarthBob88" <> wrote in
    news::

    > 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.
     
    Eric Bohlman, Nov 13, 2005
    #7
  8. DarthBob88 Guest

    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.
     
    DarthBob88, Nov 14, 2005
    #8
  9. DarthBob88 Guest

    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.
     
    DarthBob88, Nov 14, 2005
    #9
  10. Guest

    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/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).

    --
    http://DavidFilmer.com

    The best way to get a good answer is to ask a good question.
     
    , Nov 14, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Kay
    Replies:
    1
    Views:
    504
    J├╝rgen Exner
    May 18, 2004
  2. Ahmed Moustafa

    Parser for command line arguments?

    Ahmed Moustafa, Aug 21, 2003, in forum: Java
    Replies:
    0
    Views:
    399
    Ahmed Moustafa
    Aug 21, 2003
  3. SC
    Replies:
    2
    Views:
    676
    Michiel Salters
    May 5, 2004
  4. Ashe Corven

    command line arguments

    Ashe Corven, May 8, 2004, in forum: C++
    Replies:
    3
    Views:
    540
    Francis Glassborow
    May 8, 2004
  5. Replies:
    4
    Views:
    1,767
    Terry Hancock
    Apr 23, 2005
Loading...

Share This Page