Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Softpanorama Search

Introduction to Perl for Unix System Administrators

(Perl without excessive complexity)

by Dr Nikolai Bezroukov


Prev | Up | Contents | Down | Next

Homework

1. Describe steps that are required for installing Perl interpreter on Windows systems

2. Please run the following script via debugger

@s = ('h','e','l','l','o','', 'w','o','r','l','d');
$i = 0;
while ($letter = $s[$i]) {
 print "$letter";
 $i++;
}

Not that it does not print out the 'world' because of typo. You need to find why.

3. Run the script first using -w flag and then using debugger (-d flag) and find an error in the logic

print "Password? ";         # Ask for input
$pass = <STDIN>;            # Get input
chop $pass;                 # Remove the newline at the end
while ($pass ne ":SeSaM:"){ # While input is wrong.   
                            # Please  note the use of ne operator with string
    print "Sorry. Please reenter: "; # Ask again
    $a = <STDIN>;           # Get next input line
    chop $pass;             # Chop off newline again
}
print "Welcome!\n";

3. Remove a semicolon at line 3 and rerun the script. Are diagnostic messages useful?

4. Restore the semicolon; Remove opening double quite in line 4. What diagnostic messages will you get ?

5. Replace ne with != and rerun the script. Does -w flag produce any useful warning about this error

6. List most typical errors in Perl scripts that are committed by beginners.

Prev | Up | Contents | Down | Next



Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Disclaimer:

Last modified: September 05, 2009