(Perl:
Lesson 1)
{ Basic print statement,
variable assignment, and stdin }
Section 0. Background
Information |
- What is Perl
- Perl is a high-level, general-purpose,
interpreted, dynamic programming language. Perl was originally developed by
Larry Wall in 1987 as a general-purpose Unix scripting language to make
report processing easier. Since then, it has undergone many changes
and revisions and become widely popular amongst programmers. Larry Wall
continues to oversee development of the core language, and its upcoming
version, Perl 6. Perl borrows features from other programming languages
including C, shell scripting (sh), AWK, and sed. The language provides
powerful text processing facilities without the arbitrary data length limits
of many contemporary Unix tools, facilitating easy manipulation of text
files. Perl gained widespread popularity in the late 1990s as a CGI
scripting language, in part due to its parsing abilities.
- Getting Perl
- For the purposes of these perl lesson, I will
be using a perl package that comes standard on Backtrack, Ubuntu and most
flavors of Linux and Unix.
- However, if you are using Windows, instead of a
Linux, Unix or MAC operating system, you still have options.
- Pre-Requisite
-
Lab Notes
- In this lab we will do the following:
- Learn about comments and print
statements.
- Learn about basic variable string
assignments.
- Learn about standard input.
- Legal Disclaimer
- As a condition of your use of this Web
site, you warrant to computersecuritystudent.com that you will not use
this Web site for any purpose that is unlawful or
that is prohibited by these terms, conditions, and notices.
- In accordance with UCC § 2-316, this
product is provided with "no warranties, either express or implied." The
information contained is provided "as-is", with "no guarantee of
merchantability."
- In addition, this is a teaching website
that does not condone malicious behavior of
any kind.
- Your are on notice, that continuing
and/or using this lab outside your "own" test environment
is considered malicious and is against the law.
- © 2013 No content replication of any
kind is allowed without express written permission.
Section 1.
Login to BackTrack |
- Login to BackTrack
- Instructions:
- Login: root
- Password:
Whatever you changed it too
-
- Bring up the GNOME
- Instructions:
- Type startx
-
- Bring up a console terminal
- Instructions:
- Click on the Terminal Window
- Become the student user and make a directory
- Instructions:
- su - student
- mkdir -p perl_lessons
- cd perl_lessons
Section 2. Comments
and Print Statements - Create
lesson1.pl |
- Create perl script lesson1.pl
- Instructions:
- vi lesson1.pl
- Press Enter
- Creating your second script
- Instructions:
- Press "i" to get into Insert Mode
- Highlight and Copy the Below Script
- #!/usr/bin/perl
#This is a basic print statement in perl
#A "#" at the start of a line is use to create comments
#Notice How the line starts with print and the contents
#are surrounded by quotation marks.
#the \n is a hard return
print "Hello World\n";
- Edit --> Paste
- Save Your Work
- Instructions:
- Press the Esc Key
- Type ":wq!"
- Press Enter
- Run the perl script
- Instructions:
- chmod 700 lesson1.pl
- ./lesson1.pl
- You should see "Hello World" displayed
like below.
Section 3.
Variable String Assignment - Create lesson1b.pl |
- Create perl script lesson1b.pl
- Instructions:
- vi lesson1b.pl
- Press Enter
- Creating your second script
- Instructions:
- Press "i" to get into Insert Mode
- Highlight and Copy the Below Script
- #!/usr/bin/perl
#A basic variable in perl starts with a "$" sign
#To keep the explanation simple, please use quotations
#around the string that you are assigning to each variable.
#In your case, change Johnny to your first name, and Gray
#to your last name.
$first_name = "Johnny";
$last_name = "Gray";
#Notice how we placed variable after the word Hello in
#the print statement.
print "Hello $first_name $last_name\n";
- Edit --> Paste
- Save Your Work
- Instructions:
- Press the Esc Key
- Type ":wq!"
- Press Enter
- Run the perl script
- Instructions:
- chmod 700 lesson1b.pl
- ./lesson1b.pl
- You should see "Hello Johnny Gray"
displayed like below.
- Note:
- You should change Johnny Gray to your
actual name.
Section 4.
Standard Input - Create lesson1c.pl |
- Create perl script lesson1c.pl
- Instructions:
- vi lesson1c.pl
- Press Enter
- Creating your third script
- Instructions:
- Press "i" to get into Insert Mode
- Highlight and Copy the Below Script
- #!/usr/bin/perl
#Notice the first two print statements to not contain
#a \n, aka a hard return.
#Remember that a \n force the cursor to go to the
#next line
#What is chomp?
#chomp in perl will remove a \n character from a variable
#in this case
#What is stdin?
#stdin stands for stdin input.
#In this case stdin will be your first and your last names.
print "Enter Your First Name: ";
chomp($first_name = <stdin>);
print "Enter Your Last Name: ";
chomp($last_name = <stdin>);
print "Hello $first_name $last_name\n";
- Edit --> Paste
- Save Your Work
- Instructions:
- Press the Esc Key
- Type ":wq!"
- Press Enter
- Run the perl script
- Instructions:
- chmod 700 lesson1c.pl
- ./lesson1c.pl
- Note:
- Please input your actual first name and
last name.
- Proof of Lab
- Instructions
- Create a new program called
lesson1d.pl.
- This program will be very similar
to lesson1c.pl
- Have lesson1d.pl take in the following
standard input variables
- First Name
- Last Name
- Today's Date
- Note: If you use an apostrophe
in a print statement you will have to put a backslash in
front of it. (e.g.,
\').
- Email Address
- (See Expected Input in the below
Picture)
- Your output should produce FOUR
separate print lines
- (See Expected Output in the below
Picture)
- Remember to make your program
executable by doing the following:
-
Proof Of Lab Instructions:
- date
- echo "Your Name"
- Put in your actual name in place of
"Your Name"
- e.g., echo "John Gray"
- perl -c lesson1d.pl
- ./lesson1d.pl
- Press the <Ctrl> and <Alt> keys at the
same time
- Press the <PrtScn> key
- Past into a word document
- Upload to Moodle
|
 
|