SlideShare a Scribd company logo
1 of 3
Download to read offline
cs3157 – Advanced Programming
Summer 2006, Lab #1, 15 points
May 25, 2006

A first lab in perl...
    Follow these step-by-step instructions. This lab must be submitted electronically (see instructions on
class webpage, homework page) by Wednesday, May 31th, 4 pm.
    Please feel free to submit it as early as you can. Later submissions will overwrite earlier ones (in case
you find errors before the deadline).
    Please note that the point of the labs is to teach and reinforce specific programming concepts, cut time
off your homework assignment while trying to maintain your interest. If you find them tedious or
pointless, please don’t hesitate to bring it to your instructor’s attention (the same applies the opposite).
    If you decide to be creative (by all means) please make sure to note it in your README file. At
minimum the README file should specify the name of each included file and a brief description of what
they do. In addition, if you have any issues, please note them in the README file.
    You are expected to use the perl debugger in any environment you feel most comfortable.

Step 0)
If you are using your laptop, please make sure to install cygwin and perl, this will allow you to simulate
the unix environment from your laptop, so you can work offline. Else you can log in to your cs
account/cunix.
    • Create a cs3157 directory for all your labs and homework’s for this class.
    • cd into that directory and create a lab1 subdirectory for this lab.

For example:
bash# cd
bash# mkdir cs3157
bash# cd cs3157
bash# mkdir lab1
bash# cd lab1
bash# pwd
bash# ls -la
(where bash# is the unix prompt)

    Note that the instructions below give you specific names for the files that you create. Hint for doing
labs: Read through an entire step before you try to do it.
Have fun!!!


Step 1. (3 point)
Goal: basic perl usage.

   Create a basic perl script which prints out a greeting, and asks the user for their first and last name as
one string. It should then be able to print the following for someone who enters “first last”:
   1) Hello first last
   2) Your initials are F. L.
   3) Your name backwards is tsal tsrif

                                                                                                                1
Call this script hello1.pl to allow it execute you must use the chmod command. (you can check
permissions using the ‘ls –la’ in the current directory as we did in class).
bash# chmod +x hello1.pl
bash# ./hello1.pl
Note use the ‘which perl’ command to know which path to include at the top of your perl script.
bash# which perl
and it will respond with a fully qualified path, such as: /usr/local/bin/perl

Hint: See the Scalar variables section of the perl tutorial for assistance. Note that here is where the use of
double versus single quotes is important. When you use double quotes around a variable (e.g., "$a"), then
the print statement will interpret or evaluate the variable and print out its value. If you use single quotes
around a variable (e.g., ’$a’), then the print statement will NOT interpret or evaluate the variable and will
simply print $a. Try it both ways and see what happens, but make sure that you submit it the right way
(printing the value)!

Hint2: perldoc –f reverse


Step 2 (3 points)
Goal: some perl control logic

Copy your hello1.pl script to a file called game1.pl and make it run-able:
bash# cp hello1.pl game1.pl
bash# chmod +x game1.pl

    Modify it so that it plays a simple game. The program will ask you to guess how many fingers it is
holding behind it’s back (assume a little gnome is inside and they only have 10 fingers)….and once you
enter your guess, if it is correct, congratulates you, else if gives you a hint and allows you to guess one
more time.
    One more thing…..you want to time how long it took the play the game….the way to do it, is to grab
the localtime at the beginning and at the end to calculate it….just calculate minutes and hours. (i.e it took
0 hours and 10 minutes to guess wrong ☺).
    Use the built-in function localtime() to get the current time. You can read about this function if
you follow one of the links on the references page to perl built-in functions. Basically, the syntax for the
function is this:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
    Note that you call the function without an argument to get the current time. The function returns an
array, so you can call it as above, or like this:
@current_time = localtime()
and then look up the individual array entries (e.g., $current_time[0]) if that makes more sense to
you (the entries are stored in the order listed, i.e., seconds is item 0).


Step 3. (5 points)
Goal: file manipulation and advanced perl practice for the homework

   Create a perl script named step3.pl which will be used to read a text file and process it with specific
goals in mind.. Here is one way of how to run through and print out a file:
open( FH, $somefile ) || die "uh-oh problem opening $somefile $!";

                                                                                                                2
while ( <FH> ) { print "$_" }
close( FH );
This is different than dumping the entire file into an array, as sometimes we don’t have enough memory
to do the operation.

Modify the above so that it reads a file passed in as a command line argument.

We have two goals in mind
  1) We want to count the number of unique words in the file.
  2) We want to see what are the top 5 occurring words in the file (this is hard…see hint at end)
  3) We want to count the average length of words in the file.
      Hint: Perl has a built-in function called length().

For testing purposed please use the following test file which is linked on the homework page:
callw10.txt

   Do NOT submit this test file please!
   Your program should prints out the information in a friendly way — i.e., not just a number.
   Hope you remember how to read command line arguments (else see book/class notes).
Hint: so how would we count the top occurring words in your program?? The sort routine can take a
block of code to use for comparisons (perldoc –f sort)….so if you collect the counts of each word in a
hash, you would be able to say:
sort { $hsh{$b} <=> $hsh{$a} }

Please email me if this hint doesn’t make sense….

Step 4. (4 points)
Goal: working with files and md5sums, for the hw and next lab.

Create a perl script named step4.pl which will be used to help you create a log in system to authenticate
users.

You will take 3 arguments into the program
     1. username
     2. password
     3. Filename to store it in.
If the file exists you will be appending to it (no need to check for duplicates (next week lab). Each line of
the file should be the username followed by a colon, followed by the md5sum of the password
Example:
shlomo:a96a13b145eb57bf8dd14f7e0ea1e5a4
professor:8ca00feae7a4c7ced9ef1ea4aaeb197e

One way to check if you are doing it correctly is for example to create a file test.txt with the password in
it, and call md5sum (linux program) as follows:
md5sum –t test.txt

Hint: http://search.cpan.org/~gaas/Digest-MD5-2.36/MD5.pm


Please see webpage for electronic submission instructions
                                                                                                               3

More Related Content

What's hot

Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administrationvceder
 
15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unix15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unixchinkshady
 
Why Python (for Statisticians)
Why Python (for Statisticians)Why Python (for Statisticians)
Why Python (for Statisticians)Matt Harrison
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Jaganadh Gopinadhan
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionEueung Mulyana
 
Writing and using php streams and sockets
Writing and using php streams and socketsWriting and using php streams and sockets
Writing and using php streams and socketsElizabeth Smith
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_miki koganei
 
File Commands - R.D.Sivakumar
File Commands - R.D.SivakumarFile Commands - R.D.Sivakumar
File Commands - R.D.SivakumarSivakumar R D .
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossumoscon2007
 

What's hot (20)

Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Linux intro 4 awk + makefile
Linux intro 4  awk + makefileLinux intro 4  awk + makefile
Linux intro 4 awk + makefile
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administration
 
15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unix15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unix
 
Why Python (for Statisticians)
Why Python (for Statisticians)Why Python (for Statisticians)
Why Python (for Statisticians)
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
 
Python
PythonPython
Python
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Writing and using php streams and sockets
Writing and using php streams and socketsWriting and using php streams and sockets
Writing and using php streams and sockets
 
tools
toolstools
tools
 
python.ppt
python.pptpython.ppt
python.ppt
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
 
Unix 2 en
Unix 2 enUnix 2 en
Unix 2 en
 
Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_
 
File Commands - R.D.Sivakumar
File Commands - R.D.SivakumarFile Commands - R.D.Sivakumar
File Commands - R.D.Sivakumar
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 
4 text file
4 text file4 text file
4 text file
 
Unix
UnixUnix
Unix
 

Viewers also liked

Three slides of social media
Three slides of social mediaThree slides of social media
Three slides of social mediaTanner Engelman
 
brainstorm: een volgende stap...
brainstorm: een volgende stap...brainstorm: een volgende stap...
brainstorm: een volgende stap...m@rlies de vet
 
Iglu Media - Week 4
Iglu Media - Week 4 Iglu Media - Week 4
Iglu Media - Week 4 SorchaIsAGeek
 
General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]
General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]
General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]Naeem Rezghi
 
Over-The-Air Care @ Connected Car Expo.
Over-The-Air Care @ Connected Car Expo.Over-The-Air Care @ Connected Car Expo.
Over-The-Air Care @ Connected Car Expo.Mahbubul Alam
 
Support Vector Machine Classifiers
Support Vector Machine ClassifiersSupport Vector Machine Classifiers
Support Vector Machine ClassifiersAerofoil Kite
 
Alteraciones de la información genética
Alteraciones de la información genéticaAlteraciones de la información genética
Alteraciones de la información genéticaalbapmolero
 

Viewers also liked (10)

Three slides of social media
Three slides of social mediaThree slides of social media
Three slides of social media
 
brainstorm: een volgende stap...
brainstorm: een volgende stap...brainstorm: een volgende stap...
brainstorm: een volgende stap...
 
Porcentjes feria1
Porcentjes feria1Porcentjes feria1
Porcentjes feria1
 
Nabi adam as
Nabi adam asNabi adam as
Nabi adam as
 
Iglu Media - Week 4
Iglu Media - Week 4 Iglu Media - Week 4
Iglu Media - Week 4
 
General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]
General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]
General Formulation of Best Hydraulic Channel Section [Naeem Rezghi]
 
Over-The-Air Care @ Connected Car Expo.
Over-The-Air Care @ Connected Car Expo.Over-The-Air Care @ Connected Car Expo.
Over-The-Air Care @ Connected Car Expo.
 
Booklet 2
Booklet 2Booklet 2
Booklet 2
 
Support Vector Machine Classifiers
Support Vector Machine ClassifiersSupport Vector Machine Classifiers
Support Vector Machine Classifiers
 
Alteraciones de la información genética
Alteraciones de la información genéticaAlteraciones de la información genética
Alteraciones de la información genética
 

Similar to cs3157-summer06-lab1

One man loves powershell once he failed
One man loves powershell once he failedOne man loves powershell once he failed
One man loves powershell once he failedKazuhiro Matsushima
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdfharikrishnapolaki
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeProf. Wim Van Criekinge
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxalfred4lewis58146
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxSUBHI7
 
Lpi Part 2 Basic Administration
Lpi Part 2 Basic AdministrationLpi Part 2 Basic Administration
Lpi Part 2 Basic AdministrationYemenLinux
 
OS Lab Manual.pdf
OS Lab Manual.pdfOS Lab Manual.pdf
OS Lab Manual.pdfQucHunh15
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docxShiraPrater50
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxmydrynan
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxfredharris32
 
Program 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docxProgram 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docxwkyra78
 
Introduction to Linux Slides.pptx
Introduction to Linux Slides.pptxIntroduction to Linux Slides.pptx
Introduction to Linux Slides.pptxhazhamina
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercises"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercisesrICh morrow
 

Similar to cs3157-summer06-lab1 (20)

One man loves powershell once he failed
One man loves powershell once he failedOne man loves powershell once he failed
One man loves powershell once he failed
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekinge
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docx
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docx
 
Operating system lab manual
Operating system lab manualOperating system lab manual
Operating system lab manual
 
Lpi Part 2 Basic Administration
Lpi Part 2 Basic AdministrationLpi Part 2 Basic Administration
Lpi Part 2 Basic Administration
 
OS Lab Manual.pdf
OS Lab Manual.pdfOS Lab Manual.pdf
OS Lab Manual.pdf
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
 
Bioinformatica 27-10-2011-p4-files
Bioinformatica 27-10-2011-p4-filesBioinformatica 27-10-2011-p4-files
Bioinformatica 27-10-2011-p4-files
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docx
 
Shell programming
Shell programmingShell programming
Shell programming
 
MCLS 45 Lab Manual
MCLS 45 Lab ManualMCLS 45 Lab Manual
MCLS 45 Lab Manual
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
 
Program 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docxProgram 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docx
 
Lab4 scripts
Lab4 scriptsLab4 scripts
Lab4 scripts
 
Introduction to Linux Slides.pptx
Introduction to Linux Slides.pptxIntroduction to Linux Slides.pptx
Introduction to Linux Slides.pptx
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercises"PHP from soup to nuts" -- lab exercises
"PHP from soup to nuts" -- lab exercises
 
Linux basics
Linux basicsLinux basics
Linux basics
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

cs3157-summer06-lab1

  • 1. cs3157 – Advanced Programming Summer 2006, Lab #1, 15 points May 25, 2006 A first lab in perl... Follow these step-by-step instructions. This lab must be submitted electronically (see instructions on class webpage, homework page) by Wednesday, May 31th, 4 pm. Please feel free to submit it as early as you can. Later submissions will overwrite earlier ones (in case you find errors before the deadline). Please note that the point of the labs is to teach and reinforce specific programming concepts, cut time off your homework assignment while trying to maintain your interest. If you find them tedious or pointless, please don’t hesitate to bring it to your instructor’s attention (the same applies the opposite). If you decide to be creative (by all means) please make sure to note it in your README file. At minimum the README file should specify the name of each included file and a brief description of what they do. In addition, if you have any issues, please note them in the README file. You are expected to use the perl debugger in any environment you feel most comfortable. Step 0) If you are using your laptop, please make sure to install cygwin and perl, this will allow you to simulate the unix environment from your laptop, so you can work offline. Else you can log in to your cs account/cunix. • Create a cs3157 directory for all your labs and homework’s for this class. • cd into that directory and create a lab1 subdirectory for this lab. For example: bash# cd bash# mkdir cs3157 bash# cd cs3157 bash# mkdir lab1 bash# cd lab1 bash# pwd bash# ls -la (where bash# is the unix prompt) Note that the instructions below give you specific names for the files that you create. Hint for doing labs: Read through an entire step before you try to do it. Have fun!!! Step 1. (3 point) Goal: basic perl usage. Create a basic perl script which prints out a greeting, and asks the user for their first and last name as one string. It should then be able to print the following for someone who enters “first last”: 1) Hello first last 2) Your initials are F. L. 3) Your name backwards is tsal tsrif 1
  • 2. Call this script hello1.pl to allow it execute you must use the chmod command. (you can check permissions using the ‘ls –la’ in the current directory as we did in class). bash# chmod +x hello1.pl bash# ./hello1.pl Note use the ‘which perl’ command to know which path to include at the top of your perl script. bash# which perl and it will respond with a fully qualified path, such as: /usr/local/bin/perl Hint: See the Scalar variables section of the perl tutorial for assistance. Note that here is where the use of double versus single quotes is important. When you use double quotes around a variable (e.g., "$a"), then the print statement will interpret or evaluate the variable and print out its value. If you use single quotes around a variable (e.g., ’$a’), then the print statement will NOT interpret or evaluate the variable and will simply print $a. Try it both ways and see what happens, but make sure that you submit it the right way (printing the value)! Hint2: perldoc –f reverse Step 2 (3 points) Goal: some perl control logic Copy your hello1.pl script to a file called game1.pl and make it run-able: bash# cp hello1.pl game1.pl bash# chmod +x game1.pl Modify it so that it plays a simple game. The program will ask you to guess how many fingers it is holding behind it’s back (assume a little gnome is inside and they only have 10 fingers)….and once you enter your guess, if it is correct, congratulates you, else if gives you a hint and allows you to guess one more time. One more thing…..you want to time how long it took the play the game….the way to do it, is to grab the localtime at the beginning and at the end to calculate it….just calculate minutes and hours. (i.e it took 0 hours and 10 minutes to guess wrong ☺). Use the built-in function localtime() to get the current time. You can read about this function if you follow one of the links on the references page to perl built-in functions. Basically, the syntax for the function is this: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(); Note that you call the function without an argument to get the current time. The function returns an array, so you can call it as above, or like this: @current_time = localtime() and then look up the individual array entries (e.g., $current_time[0]) if that makes more sense to you (the entries are stored in the order listed, i.e., seconds is item 0). Step 3. (5 points) Goal: file manipulation and advanced perl practice for the homework Create a perl script named step3.pl which will be used to read a text file and process it with specific goals in mind.. Here is one way of how to run through and print out a file: open( FH, $somefile ) || die "uh-oh problem opening $somefile $!"; 2
  • 3. while ( <FH> ) { print "$_" } close( FH ); This is different than dumping the entire file into an array, as sometimes we don’t have enough memory to do the operation. Modify the above so that it reads a file passed in as a command line argument. We have two goals in mind 1) We want to count the number of unique words in the file. 2) We want to see what are the top 5 occurring words in the file (this is hard…see hint at end) 3) We want to count the average length of words in the file. Hint: Perl has a built-in function called length(). For testing purposed please use the following test file which is linked on the homework page: callw10.txt Do NOT submit this test file please! Your program should prints out the information in a friendly way — i.e., not just a number. Hope you remember how to read command line arguments (else see book/class notes). Hint: so how would we count the top occurring words in your program?? The sort routine can take a block of code to use for comparisons (perldoc –f sort)….so if you collect the counts of each word in a hash, you would be able to say: sort { $hsh{$b} <=> $hsh{$a} } Please email me if this hint doesn’t make sense…. Step 4. (4 points) Goal: working with files and md5sums, for the hw and next lab. Create a perl script named step4.pl which will be used to help you create a log in system to authenticate users. You will take 3 arguments into the program 1. username 2. password 3. Filename to store it in. If the file exists you will be appending to it (no need to check for duplicates (next week lab). Each line of the file should be the username followed by a colon, followed by the md5sum of the password Example: shlomo:a96a13b145eb57bf8dd14f7e0ea1e5a4 professor:8ca00feae7a4c7ced9ef1ea4aaeb197e One way to check if you are doing it correctly is for example to create a file test.txt with the password in it, and call md5sum (linux program) as follows: md5sum –t test.txt Hint: http://search.cpan.org/~gaas/Digest-MD5-2.36/MD5.pm Please see webpage for electronic submission instructions 3