eee274 lab1 report

5
EEE 274 ADVANCED TIMING ANALYSIS FALL 2010 PROJECT – I DATE: 10/20/2010 INSTRUCTOR: PREPARED BY: Dr. JING PANG Madhusudhan Nukhathoti Arjun Vishwanathan Raju

Upload: arjun-varadharajan

Post on 09-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EEE274 LAB1 Report

8/8/2019 EEE274 LAB1 Report

http://slidepdf.com/reader/full/eee274-lab1-report 1/5

EEE 274 ADVANCED TIMING ANALYSIS

FALL 2010

PROJECT – I

DATE: 10/20/2010

INSTRUCTOR: PREPARED BY:

Dr. JING PANG Madhusudhan NukhathotiArjun Vishwanathan Raju

Page 2: EEE274 LAB1 Report

8/8/2019 EEE274 LAB1 Report

http://slidepdf.com/reader/full/eee274-lab1-report 2/5

Part 1. 

Write a perl program to copy the content of “gpa.txt” into another new text filecalled “gpa_copy.txt”.In addition, on the screen, print out the rows of “gpa.txt” which includes 4.0 GPA.# gpa.txt

Name GPAAsd 4.0Sdf 3.2Fghsd 3.6Qwer 4.0

Program Code:

#!user/local/bin/perl#$s=shift @ARGV;$s="gpa.txt";#$d=shift @ARGV;

$d="gpa_copy.txt";open(KK,$s);@lines=<KK>;#print @lines; print "\n\n";open(IN,'<',$s) or die "cant read source file\n";open(OUT,'>',$d) or die "cant read dest file\n";while(<IN>){ print OUT;}

close (IN);close (OUT);

sub patt{foreach (@lines){ print "$_\n" if /$pattern/;}#print "\n";}$pattern= '[4]';

&patt;close (KK);

Page 3: EEE274 LAB1 Report

8/8/2019 EEE274 LAB1 Report

http://slidepdf.com/reader/full/eee274-lab1-report 3/5

Output:

Asd 4.0

Qwer 4.0

Result:

The required result was copied in the file “gpa_copy.txt” and was displayed in the output.

PART 2Use the following regular expression for pattern matching, show the results andgive a short discussionof the functionality of the regular expression from (1) to (9)sub print_array{ for ($i=0; $i<=$#strings;$i++){print $strings[$i], "\n";}print "\n\n";}sub grep_pattern{ foreach (@strings){print "$_\n" if /$pattern/;}print "\n\n";}

### Setting up the Array of strings@strings = ("eee, 2, 7, four", "Perl is great", "1, Three", "Five, 7","This is exercise in Perl");(1). $pattern = '\d';(2). $pattern = '\d+.+';(3). $pattern = '\d+$';(4). $pattern = 'e+'(5). $pattern = 'e*'(6). $pattern = 'e?'(7). $pattern = '\bis\b'(8). $pattern = '\b \w{4} \b'(9). $pattern = '^[A-Z] '

Program Code:

#!usr/local/bin/perl@strings=("eee, 2, 7, four", "Perl is great", "1, Three", "Five, 7", "This is exercise in Perl");sub print_array{ print "\n\n";for ($i=0; $i<=$#strings; $i++)

Page 4: EEE274 LAB1 Report

8/8/2019 EEE274 LAB1 Report

http://slidepdf.com/reader/full/eee274-lab1-report 4/5

{ print $strings[$i], "\n";} print "\n\n";}

sub grep_pattern{foreach (@strings){ print "$_\n" if /$pattern/;} print "\n\n";}&print_array;$pattern = '[2]';&grep_pattern;

Output:

(1). $pattern = '\d';

Displays lines containing digits

eee, 2, 7, four 1, ThreeFive, 7

2. $pattern = '\d+.+';

Displays lines containing one or more occurrences of digits

eee, 2, 7, four 1, Three

(3). $pattern = '\d+$';

Displays lines starting with any character and ending with digits

Five, 7

4). $pattern = 'e+'

Displays lines containing one or more occurrences of letter ‘e’

eee, 2, 7, four Perl is great1, ThreeFive, 7This is exercise in Perl

Page 5: EEE274 LAB1 Report

8/8/2019 EEE274 LAB1 Report

http://slidepdf.com/reader/full/eee274-lab1-report 5/5

(5). $pattern = 'e*'

Display lines that have zero or more occurrences of letter ‘e’

eee, 2, 7, four Perl is great1, ThreeFive, 7This is exercise in Perl

(6). $pattern = 'e?'

Displays lines that have one or more occurrence of letter ‘e’.

eee, 2, 7, four 

Perl is great

1, ThreeFive, 7This is exercise in Perl

(7). $pattern = '\b is \b'

Displays lines that have the word ‘is’

Perl is great

This is exercise in Perl

(8). $pattern = ' \b \w{4} \b'

Display lines with a word boundary of 4 words or more

This is exercise in Perl

(9). $pattern = '^[A-Z] '

Displays the lines starting and ending with alphabets…

Perl is great

Five, 7This is exercise in Perl