(Perl:
Lesson 3)
{ Learning about IF/ELSE
Statements }
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:
- We will download an IF/ELSE program.
- We will create a program that takes in
standard input and analyzes it with IF/ELSE statements.
- 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 |
- Start Up VMWare Player
- Instructions:
- Click the Start Button
- Type Vmplayer in the search box
- Click on Vmplayer
-
- Open a Virtual Machine
- Instructions:
- Click on Open a Virtual Machine
-
- Open the BackTrack5R1 VM
- Instructions:
- Navigate to where the BackTrack5R1 VM
is located
- Click on on the BackTrack5R1 VM
- Click on the Open Button
-
- Edit the BackTrack5R1 VM
- Instructions:
- Select BackTrack5R1 VM
- Click Edit virtual machine settings
-
- Edit Virtual Machine Settings
- Instructions:
- Click on Network Adapter
- Click on the Bridged Radio button
- Click on the OK Button
- Play the BackTrack5R1 VM
- Instructions:
- Click on the BackTrack5R1 VM
- Click on Play virtual machine
-
- Login to BackTrack
- Instructions:
- Login: root
- Password: toor or <whatever you changed
it to>.
-
- Bring up the GNOME
- Instructions:
- Type startx
-
Section 2.
Bring up a
console terminal |
- Start up a terminal window
- Instructions:
- Click on the Terminal Window
- Obtain the IP Address
- Instructions:
- ifconfig -a
- Note(FYI):
- My IP address 192.168.1.111.
- In your case, it will probably be
different.
-
Section 3.
Download lesson3a.pl |
- Become the student user and make a directory
- Instructions:
- su - student
- mkdir -p perl_lessons
- cd perl_lessons
- Create perl script lesson3a.pl
- Instructions:
- wget http://www.computersecuritystudent.com/UNIX/PERL/lesson3/lesson3a.pl
- ls -l lesson3a.pl
- Creating your script
- Instructions:
- chmod 700 lesson3a.pl
- ./lesson3a.pl
- Analyze the Script
- Note(FYI):
- The program contains 4 different IF
Statement.
- Read the code line by line, and
understand how each IF Statement functions.
- Once you feel confortable, move on to
the proof of lab section.
- Project
- Instructions:
- Write a program called lesson3b.pl
- The program should ask you a question
- e.g., print "Enter a number: ";
- The program should assign variable $i
to standard input
- i.e., chomp(my $i = <stdin>);
- The program should contain a Multi
IF/ELSE statement that performs the following tests
- If $i is less than 2
- If $i is less OR equal to 5
- if $i is greater than 5
- Proof of Lab
- Instructions
- chmod 700 lesson3b.pl
- ./lesson3b.pl
- ./lesson3b.pl
- ./lesson3b.pl
- date
- echo "Your Name"
- Put in your actual name in place of
"Your Name"
- e.g., echo "John Gray"
- Do a PrtScn, Paste into a word
document, and upload to Moodle.
-
Proof Of Lab Instructions:
- Press the PrtScn key
- Paste into a word document
- Upload to Moodle
|
 
|