Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Please Help

by kcott (Archbishop)
on Sep 29, 2012 at 23:28 UTC ( [id://996436]=note: print w/replies, xml ) Need Help??


in reply to Please Help

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://996436]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found