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

4) Complete the script to accomplish the following tasks using Perl built-in fun

ID: 3714465 • Letter: 4

Question

4) Complete the script to accomplish the following tasks using Perl built-in functions: (10 pts.) %friends = ( Gary Lucy an ->"Dallas". => "Exeter". "Reading", Samantha>"Oregon", va "Deven". Julia -Tokyp" a) Print only the keys from the hash b) Print only the values from the hash c) Print both keys and values 5) Write a script to read a file (motd.dat) assuming that the file hast multiple message. Print one message at the time (hint: you may need to use the line record separator). (10 pts.)

Explanation / Answer

4.a )Answer-:

#perl 5.22.1

my %friends = ( Garry=>"Dallas", Lucy=>"Exeter", Ian=>"Reading",Samantha=>"Oregon",Eva=>"Deven",Julia=>"Tokyp");
my @k = keys %friends;
print "@k ";

b.Ans-:print values of list

#perl 5.22.1
my %friends = ( Garry=>"Dallas", Lucy=>"Exeter", Ian=>"Reading",Samantha=>"Oregon",Eva=>"Deven",Julia=>"Tokyp");
my @v= values %friends;
print "@v ";

4.c Ans-: print keys and values both

#perl 5.22.1
my %friends = ( Garry=>"Dallas", Lucy=>"Exeter", Ian=>"Reading",Samantha=>"Oregon",Eva=>"Deven",Julia=>"Tokyp");

my @k= keys %friends;
my @v= values %friends;

while( my( @k, @v ) = each %friends ){
print "@k @v ";
}

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