G'day cpom1,

Welcome to the monastery.

The following should be sufficient information for you to complete your class assignment.

The perldoc.perl.org site should provide most, if not all, of the documentation you need while initially learning Perl. I have it bookmarked and use it often; I suggest you do the same. I've included a number of links to documentation below - all to pages on this site.

After the shebang line (that's the #!... on line 1) put:

use strict; use warnings;

When you do this, Perl will tell you about mistakes you've made or potentially problematic code you're attempting to run. While you're learning Perl, you should do this in all of your scripts. See strict and warnings.

The line read -p "What is your name: " name is not Perl: it works in bash (and probably other shells). The typical way to achieve what you want here is with something like:

print 'Prompt message: '; my $reply = <>; print $reply;

The first line should be self-explanatory - single-quotes are for literal text (see print).

In the next line my declares a lexical variable: Perl has various types of variables - you'll use this type most often and it's all you need for this type of script. Unlike bash, where you assign to varname then read from $varname, in Perl you use $varname in both cases. The <> reads from standard input (in your case, this is what you type at the keyboard). One important point to note is that it reads the text you type as well as the newline you enter to terminate your input. You can read about it in perlop - I/O Operators but you may find that rather heavy going: it certainly has far more information than you need for this script.

Finally, you print whatever the user typed, including the newline.

That handles getting the input you need. Note that there's no checking of this input: the user could have just typed a newline for name and something that isn't a number for income. I suspect that's not a requirement for your assignment: add a comment in your code stating that no validation is performed to indicate that you are aware of this limitation in your script. (If it is a requirement, come back and ask a follow-up question.)

All of your conditions use bash (or other shell) code again (-lt and -gt). See perlop - Relational Operators for the Perl equivalents - note that there's different operators for string and numerical comparisons.

That should be enough to get your script up and running. Here's a few additional links you may find useful: perl; perlsyn; perlstyle.

-- Ken


In reply to Re: Please Help by kcott
in thread Please Help by cpom1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.