Getting Set up to work with Perl the First time on a Machine: Install Perl, DOS Setup
Starting a Perl Sessions - After the first time: DOS directory & path, Windows Editor
A sequence of Perl programs for beginners:
| 1 | one liner | print "Hello World!"; |
|
| 2 | New Line | print "\nHello World\n"; |
|
| 3 | More lines |
print "\n"; |
|
| 4 | variable | $var1 = 16; print $var1; |
|
| 5 | more variables |
|
|
| 6 | text variables |
|
|
| 7 | errors | $varT ="This line does not end with a semicolon" |
|
| 8 | more text variables |
|
|
| 9 | still more text variables | $var1 = "First line"; $var2 = "second line"; print "This is better:\n $var1 \n$var2\n"; |
|
| 10 | User input (a) |
|
|
| 11 | User input (b) |
|
|
| 12 | User input (c) | print "Enter your name:"; $name = <STDIN>; chop ($name); print "\nHello $name, how are you?\n"; |
|
| User input (c) |
print "Enter your name:"; |
||
| Loops (a) | $count = 0; while ($count < 10) { print "This is loop number $count\n"; $count = $count + 1; } |
||
| loops (b) |
|
||
| Comments | print "Anything following a \# on a line is ignored\n"; #this is ignored # and so is this # print "fudge"; #and this line wont work till the first # is removed |
||
| "If" statements (a) |
$uMean = 42; # that funny looking == is two of these "="
in a row. In comparing numbers in Perl |
||
| "If" (b) | See if you can figure out how to modify the above program (If (a) ) so that the user keeps guessing until the right answer is guessed. Hint: Use a loop! Click here to see the answer. |
||
| "if (c) | In program # above you learned how to program a loop using a "while" statement. Now that you know how to use "if" statements, see if you can build a loop without using a "while" statement. Hint: Use an "if" statement! |
||
|
variables ( like $var1, $uGuess etc.) |
|||
The next lesson in this format will cover how to read text from a file and how to put text into a file. |