Lecture%2026%20-Course%20Review-2

Lecture%2026%20-Course%20Review-2 - Ananda Gunawardena...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Ananda Gunawardena Lecture 26 Course Review II Perl Programming Basics This is only a partial list of tasks that you should know. Anything else can be found by using the man pages > man perl and use the specific pages to find information. For example, >man perlintro gives you a basic introduction to perl. This documentation is available to you during the test. Declare a variable: $myname = ‘guna’; Print a variable: print $myname; Open a file : open(INFILE, “filename”); Read a file: foreach $line (<INFILE>) { do_something } Chop the newline: chomp($line) Split a String: @array = split(/regex/, $line) Find the Sum: $sum = 0; for ($i=0 ; $i<$size; $i++) { $sum += $i; } Check if the file name is “guna”: if ($file eq ‘guna’) { do_something } Open a dir and read files: opendir(DIR,”.”); foreach $file (readdir(DIR) ){ . . } Make a directory: mkdir $dirname; Remove a directory: rmdir $dirname; Command Line Arguments: $#ARGV – index of last argument, $ARGV[0] – first arg Running a perl script from another: system ‘perl program.pl text.txt’ [1] Suppose you are given a complete Perl program findMaxScore.pl that takes any number of integer arguments and find the max score. Write a Perl program that takes a a grade.txt file, and computes the max score for each of the users. Output the max scores to
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Lecture%2026%20-Course%20Review-2 - Ananda Gunawardena...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online