Question

How do you write a perl script called myscript.pl to determine how many logins occurred for...

How do you write a perl script called myscript.pl to determine how many logins occurred for user "abc123456" from myusersfile.txt?

content in mysuerfile.txt are user id "abc123455", user id "abc123456" and user id "abc123457". But we want to know how many times did user id abc123456 login the system.

Homework Answers

Answer #1

Executable Code:

my $file = 'myusersfile.txt';
my $word= 'abc123456';
$count =0;
# Open the file
open my $fh, '<', $file or die "Could not open '$file' $!\n";
# Read each line
while (my $row = <$fh>) {
chomp $row;
# If abc123456 found
if ($row eq $word) {
#Increment count
$count++;
}
}
print "The number of logins for user abc123456 is ";
print $count;
print "$!\n"

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(At least) How many times did endoskeletons arise, and how do we know? (Topic: Deuterostomes/Echinoderms)
(At least) How many times did endoskeletons arise, and how do we know? (Topic: Deuterostomes/Echinoderms)
Bash script Suppose you are working as a prof or TA and your students have an...
Bash script Suppose you are working as a prof or TA and your students have an assignment which requires them each to hand in exactly one file. You've got a directory with all of the submitted files in it, and no other files. You're also lucky enough to have a script that will do all the work of marking a submission; it will take the name of a submission file as its only parameter and will print out a single...
How do we know how many genes control development in an organism like Drosophila? And how...
How do we know how many genes control development in an organism like Drosophila? And how did we discover that selector genes specify which adult structures will be formed by body segments? Additionally, how do we know that eye formation in all animals is controlled by a binary switch gene?
how do you determine the size of a pipe?, a pipe to use from a pump...
how do you determine the size of a pipe?, a pipe to use from a pump to a boiler suction side and discharge side, if you want them to be equal, the pressure at the pump and at the boiler is equal? , if you know the volume flow rate and the pressure of both the pump and the boiler
What does CaCl2, MgSO4 or Na2SO4 do? How do you know if you have added enough...
What does CaCl2, MgSO4 or Na2SO4 do? How do you know if you have added enough to the organic layer? What must have occurred if you added MgSO4 to an Erlenmeyer flask containing a colorless solution and it all dissolved? type do not write
How do you know if you picked an excellent topic to write A paper on?
How do you know if you picked an excellent topic to write A paper on?
8) Write Python code for a function called occurances that takes two arguments str1 and str2,...
8) Write Python code for a function called occurances that takes two arguments str1 and str2, assumed to be strings, and returns a dictionary where the keys are the characters in str2. For each character key, the value associated with that key must be either the string ‘‘none’’, ‘‘once’’, or ‘‘more than once’’, depending on how many times that character occurs in str1. In other words, the function roughly keeps track of how many times each character in str1 occurs...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of Circle. The user will have the ability to convert Area OR the Circumference. That means we need to add a decision structure to the program. Furthermore, they need to be able to do it as many times as they want. That means we need to add a main loop structure to the program. The user will also have the choice of whether to run...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
You are looking for a way to incentivize the sales reps that you are in charge...
You are looking for a way to incentivize the sales reps that you are in charge of. You design an incentive plan as a way to help increase in their sales. To evaluate this innovative plan, you take a random sample of your reps, and their weekly incomes before and after the plan were recorded. You calculate the difference in income as (after incentive plan - before incentive plan). You perform a paired samples t-test with the following hypotheses: Null...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT