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

Modify the Perl program lab10e.pl so that it prints the user id of the person wh

ID: 3815520 • Letter: M

Question

Modify the Perl program lab10e.pl so that it prints the user id of the person who had the maximum length session. Do not use the total time for any user for comparison purposes; instead consider the lengths of individual sessions. For example, if the file shows that user1 had two log in sessions that lasted 2 hours each and user2 had a single log-in session that lasted 3 hours, and every one of the other 7 login sessions lasted 30 minutes each, the program must print user2, not user1. (user1 had a combined total of 4 hours, but the maximum session length was 3 hours and that was by user2.)

$ ./lab10p2.pl signindata

cat lab10e.pl /usr/bin/perl -w open (FILE, SARGV[0]) or die("Could not open the file $ARGV10]"); while ($line FILE if ($line ISARGVI1V) $beginning, $time) split(M', $line (Shour, $min split( Stime Smin split()", $mini Ssum Shour 60 $min $sum print "Total time init($sum 160)," hours and $sum 60, minutes close(FILE Run the program.s ./lab10e.pl signindata cfs264fa160110 Name "main: beginning" used only once: possible typo at ./lab Total time 8 hours and 54 minutes How to write a shell script to solve the problem discuss

Explanation / Answer

#!/usr/bin/perl -w
open(FILE, $ARGV[0]) or die("Could not open the file $ARGV[0]");
$max_time = -1;
$max_id = "";
while ($line = <FILE>){
($user_id, $line) = split(' ', $line, 2);
(undef, $time) = split('(', $line);
($hour, $min) = split(':', $time);
($min) = split(')', $min);
$time = $hour*60 + $min;
if ($time > $max_time)
{
$max_time = $time;
$max_id = $user_id;
}
}

print "User id with maximum session length ", $max_id, " ";
close(FILE);

to run execute

./lab10e.pl signindata

Sample output

User id with maximum session length cfs264fa160120

signindata

fs264fa160116 pts/2 10.10.76.222 Mon Oct 24 17:16 18:00 (00:43)
cfs264fa160119 pts/o 204.77.41.129 Mon Oct 24 16:27 17:50 (01:22)
cfs264fa160120 pts/4 73.94.110.23 Mon Oct 24 13:08 17:53 (04:44)
cfs264fa160113 pts/3 73.37.142.145 Mon Oct 24 13:07- 13:42 (00:34)
cfs264fa160110 pts/2 73.94.120.153 Mon Oct 24 12:52 15:22 (02:30)
cfs264fa1607 pts/4 50.225.90.17 Mon Oct 24 11:43 12:27 (00:44)
cfs264fa160108 pts/3 69.180.183.31 Mon Oct 24 10:36 12:14 (01:38)
cfs264fa160110 pts/0 73.94.121.91 Mon Oct 24 10:34 13:58 (03:23)
cfs264fa160110 pts/2 73.94.123.63 Mon Oct 24 09:23 12:24 (03:01)
ics499fa160124 pts/2 69.180.183.222 Mon Oct 24 07:29 08:08 (00:39)

Please rate positively if this answered your query.

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