Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help to pass this Perl EXAM. Class: COSC 206.0 (Applied Programming II) E

ID: 3686220 • Letter: I

Question

I need help to pass this Perl EXAM.

Class:              COSC 206.0 (Applied Programming II)

Exam:              02

Submission:    Email source code and submit hard copy prior to due date.

Due Date: 7 APR 2016

Topic:              Perl and regular expressions

Instructions:

For each of the following, select the answer that best represents the output of this program.

Problem 01:

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "Let’s rent a bus!";

     s/(.)(w).*().*(.)$/$1$2$3$4/ ;

     print "[" ;    print ;   print "]";

     exit;

                        A.        [ett!]

                        B.        [Lett!]

                        C.        [Lee!]

                        D.        [Let’s rent a bus!]

                        E.         none of the above.

Problem 02:

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "*The only true wisdom is knowing you know nothing.*";

     /(w+){2}.*/;

     #s/(w+){2}.*/1/ ;

     print "[" ;

     if (defined $& ) { print $& ; } else { print "undef"; }

     print "]";

     exit;

                        A.        [ng.*]

                        B.        [The]

                        C.        [undef]

                        D.        [*Th]

                        E.         none of the above.

Problem 03:

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "Tom loves driving fast cars.";

     $_ = "His car can go from [0-60]mph in 3.5 seconds.";

     /d.d{2}./;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [3.5 ]

                        B.        [undef]

                        C.        [0-60m]

                        D.        [0-60]]

                        E.         none of the above.

Problem 04:

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "What do you call a computer that can sing? A Dell!";

     /S*$/;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [Dell]

                        B.        [A Dell!]

                        C.        [Dell!]

                        D.        [ Dell!]

                        E.         none of the above.

Problem 05.

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "Python.";

     $_ .= " This is plagiarism.";

     $_ .= " You can't just import essay.";

     /.*?./;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [y.]

                        B.        [plagiarism.]

                        C.        [essay.]

                        D.        [Python.]

                        E.         none of the above.

Problem 06.

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "Why did the programmer quit his job? ";

     $_ .= "Because he didn't get arrays.";

     /[^.*?(w+)].*dw{2}s/;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [ did ]

                        B.        [didn't ]

                        C.        [didn't g]

                        D.        [didn]

                        E.         none of the above.

Problem 07.

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "*Why do Java developer wear glasses? ";

     $_ .= "Because they don't C#!*";

     /.**.../;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [C#!*]

                        B.        [#!*]

                        C.        [*Why]

                        D.        [*Why ]

                        E.         none of the above.

Problem 08.

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "*Why do Java developer wear glasses? ";

     $_ .= "Because they don't C#!*";

     /.**(...)?/;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [C#!*]

                        B.        [#!*]

                        C.        [*Why]

                        D.        [*Why ]

                        E.         none of the above.

Problem 09.

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "the quick brown fox jumps over a lazy dog.";

     /.sd..(.)/;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [y dog]

                        B.        [undef]

                        C.        [e qui]

                        D.        [k bro]

                        E.         none of the above.

Problem 10.

     #!/usr/bin/perl

     use strict;

     use warnings;

     $_ = "pneumonoultramicroscopicsilicovolcanoconiosi";

     /[r|i][m|o][s|l]|[i|c][v|o][n|p]/;

     print "[" . (( defined $& ) ? $& : "undef" ) . "]";

     exit;

                        A.        [ioslcop]

                        B.        [microv]

                        C.        [rolivp]

                        D.        [roscop]

                        E.         none of the above.

                       

Problem 11:

     #!/usr/bin/perl

     use strict;

     use warnings;

     my $str = "It's 106 miles to Chicago,”

        $str .= “ we got a full tank of gas,”

        $str .= “ half a pack of cigarettes,”

        $str .= “ it's dark, and we're wearing sunglasses.";

     if ( $str =~ m/[gas]/ ) { print “[$&]”; }

     else {    print “[undef]”;     }

     exit;

                        A.        [gas]

                        B.        [undef]

                        C.        [g]

                        D.        [s]

                        E.         none of the above.

Problem 12:

     #!/usr/bin/perl

     use strict;

     use warnings;

     my $str = “How many rings do you need to rule them all?”;

     $str =~ s/.(w).*(w)(w)...*?/$1$2$3/;

     print $str;

     exit;

                        A.        [undef]

                        B.        [oem]

                        C.        [one]

                        D.        [o a]

                        E.         none of the above.

Problem 13.

     #!/usr/bin/perl

     use strict;

     use warnings;

     my $str = “This is a test string”;

     $str =~ s/is.*st/(THIS IS THE MATCH REGION)/;

     print $str;

     exit;

                        A.        [Th(THIS IS THE MATCH REGION) string]

                        B.        [Th(THIS IS THE MATHC REGION)ring]

                        C.        [This (THIS IS THE MATCH REGION) string]

                        D.        [This (THIS IS THE MATCH REGION)ring]

                        E.         none of the above.

Problem 14.

     #!/usr/bin/perl

     use strict;

     use warnings;

     my $str = “ COSC 206: 2016 Golf Outing”;

     if ( $str =~ m/dddd?/ ) { print “[$&]”; }

     else {    print “[undef]”;     }

     exit;

                        A.        [2016]

                        B.        [206]

                        C.        [206:]

                        D.        [undef]

                        E.         none of the above.

Problem 15.

     #!/usr/bin/perl

     use strict;    use warnings;

     my $str = “This is a test string”;

     $_ = $str;

     /a/;

     if ( $str =~ /[ +]/) {   print "[$&]"; }

     else {

          if ( defined $& ) { print "[$&]"; }

          else {    print "[undef]";     }

     }

     exit;

                        A.        [         ]

                        B.        [    ]

                        C.        [t+]

                        D.        [undef]

                        E.         none of the above.

Problem 16.

     #!/usr/bin/perl

     use strict;use warnings;

     open(FHIN,"exam_input.txt") or die"Oh no!:$! ";

     chomp(my@lines=);close(FHIN);

     my@lines2=grep(/Invalid/,grep(/SSHD/,@lines));

     foreach(@lines2){shift@lines2 if(/ubnt/)}

     print"Size=".@lines2." ";

     exit;

                        A.        Size=1

                        B.        Size=2

                        C.        Size=3

                        D.        Size=4

                        E.         none of the above.

Contents of file exam_input.txt:

2016-04-03T11:45:06.604047-04:00 yr2 run-crons[5154]: suse-texlive: OK

2016-04-03T11:45:06.637583-04:00 yr2 su: (to root) root on (null)

2016-04-03T11:45:06.637821-04:00 yr2 su: pam_unix(su:session): session opened for user nobody$

2016-04-03T11:45:06.640507-04:00 yr2 su: pam_unix(su:session): session closed for user nobody

2016-04-03T11:45:06.643282-04:00 yr2 su: (to root) root on (null)

2016-04-03T11:45:06.650073-04:00 yr2 su: pam_unix(su:session): session opened for user nobody$

2016-04-03T11:45:15.397003-04:00 yr2 su: pam_unix(su:session): session closed for user nobody

2016-04-03T11:45:15.554708-04:00 yr2 run-crons[5154]: suse-updatedb: OK

2016-04-03T11:45:15.570149-04:00 yr2 run-crons[5154]: suse.cron-sa-update: OK

2016-04-03T11:45:15.624610-04:00 yr2 run-crons[5154]: suse.de-backup-rc.config: OK

2016-04-03T11:45:17.628402-04:00 yr2 named[1731]: client 127.0.0.1#51885 (connect.facebook.ne$

2016-04-03T11:45:17.628638-04:00 yr2 named[1731]: client 127.0.0.1#51885 (connect.facebook.ne$

2016-04-03T11:45:17.644924-04:00 yr2 named[1731]: client 127.0.0.1#55419 (connect.facebook.ne$

2016-04-03T11:45:17.645102-04:00 yr2 named[1731]: client 127.0.0.1#35966 (analytics.twitter.c$

2016-04-03T11:45:17.645271-04:00 yr2 named[1731]: client 127.0.0.1#35966 (analytics.twitter.c$

2016-04-03T12:05:04.481516-04:00 yr2 sshd[18772]: Invalid user support from 185.110.132.54

2016-04-03T12:05:04.482486-04:00 yr2 sshd[18772]: input_userauth_request: invalid user suppor$

2016-04-03T12:05:04.657118-04:00 yr2 sshd[18772]: Received disconnect from 185.110.132.54:

Explanation / Answer

Problem 01:
#!/usr/bin/perl
use strict;
use warnings;
$_ = "Let’s rent a bus!";
s/(.)(w).*().*(.)$/$1$2$3$4/ ;
print "[" ; print ; print "]";
exit;

output : [Lee!]

Problem 02:
#!/usr/bin/perl
use strict;
use warnings;
$_ = "*The only true wisdom is knowing you know nothing.*";
/(w+){2}.*/;
#s/(w+){2}.*/1/ ;
print "[" ;
if (defined $& ) { print $& ; } else { print "undef"; }
print "]";
exit;

output : [The]

Problem 03:
#!/usr/bin/perl
use strict;
use warnings;
$_ = "Tom loves driving fast cars.";
$_ = "His car can go from [0-60]mph in 3.5 seconds.";
/d.d{2}./;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;

Output: [0-60]]

Problem 04:
#!/usr/bin/perl
use strict;
use warnings;
$_ = "What do you call a computer that can sing? A Dell!";
/S*$/;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;

Output: [Dell!]

Problem 05.
#!/usr/bin/perl
use strict;
use warnings;
$_ = "Python.";
$_ .= " This is plagiarism.";
$_ .= " You can't just import essay.";
/.*?./;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;
Output: [Python.]

Problem 06.
#!/usr/bin/perl
use strict;
use warnings;
$_ = "Why did the programmer quit his job? ";
$_ .= "Because he didn't get arrays.";
/[^.*?(w+)].*dw{2}s/;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;

Output: [ did ]

Problem 07.
#!/usr/bin/perl
use strict;
use warnings;
$_ = "*Why do Java developer wear glasses? ";
$_ .= "Because they don't C#!*";
/.**.../;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;

Output: [*Why]

Problem 08.
#!/usr/bin/perl
use strict;
use warnings;
$_ = "*Why do Java developer wear glasses? ";
$_ .= "Because they don't C#!*";
/.**(...)?/;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;

Output: [*Why]

Problem 09.
#!/usr/bin/perl
use strict;
use warnings;
$_ = "the quick brown fox jumps over a lazy dog.";
/.sd..(.)/;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;

Output : [y dog]

Problem 10.
#!/usr/bin/perl
use strict;
use warnings;
$_ = "pneumonoultramicroscopicsilicovolcanoconiosi";
/[r|i][m|o][s|l]|[i|c][v|o][n|p]/;
print "[" . (( defined $& ) ? $& : "undef" ) . "]";
exit;
Output:[ros]

Problem 11:
#!/usr/bin/perl
use strict;
use warnings;
my $str = "It's 106 miles to Chicago,”
$str .= “ we got a full tank of gas,”
$str .= “ half a pack of cigarettes,”
$str .= “ it's dark, and we're wearing sunglasses.";
if ( $str =~ m/[gas]/ ) { print “[$&]”; }
else { print “[undef]”; }
exit;

Output: Runtime error   time

Problem 12:
#!/usr/bin/perl
use strict;
use warnings;
my $str = “How many rings do you need to rule them all?”;
$str =~ s/.(w).*(w)(w)...*?/$1$2$3/;
print $str;
exit;

Output: Runtime error   time: 0 memory: 6132 signal:-1

Problem 13.
#!/usr/bin/perl
use strict;
use warnings;
my $str = “This is a test string”;
$str =~ s/is.*st/(THIS IS THE MATCH REGION)/;
print $str;
exit;

Output: Compilation error

Problem 14.
#!/usr/bin/perl
use strict;
use warnings;
my $str = “ COSC 206: 2016 Golf Outing”;
if ( $str =~ m/dddd?/ ) { print “[$&]”; }
else { print “[undef]”; }
exit;
Output: Compilation error

Problem 15.
#!/usr/bin/perl
use strict; use warnings;
my $str = “This is a test string”;
$_ = $str;
/a/;
if ( $str =~ /[ +]/) { print "[$&]"; }
else {
if ( defined $& ) { print "[$&]"; }
else { print "[undef]"; }
}
exit;

Output: Compilation error

Problem 16.
#!/usr/bin/perl
use strict;use warnings;
open(FHIN,"exam_input.txt") or die"Oh no!:$! ";
chomp(my@lines=);close(FHIN);
my@lines2=grep(/Invalid/,grep(/SSHD/,@lines));
foreach(@lines2){shift@lines2 if(/ubnt/)}
print"Size=".@lines2." ";
exit;

Output: Compilation error

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote