Question

Write a perl script to accomplish following tasks: 1. Prompt user to enter their name and...

Write a perl script to accomplish following tasks:

1. Prompt user to enter their name and age, and then calculate and display their age in days.

2. Initialize a 20-element array of numbers and print each element.

3. Get a system host name.

4. Get a web page and save it to a file.

5. List background services (daemons) on your system.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

please find the scripts and output below.

kindly upvote

1>

#!/usr/bin/perl
use strict;
use warnings;

#TASK: Ask the user for her name and age
#and calculate her age in days
#get a string from the keyboard
print "Please enter your sweet name\n";
my $name = <STDIN>;
#getting rid of the new line character
#try leaving this line out
chomp($name);
#prompt the user for his/her age
#get a number from the keyboard
print "$How old are you?\n";
my $age = <>;
chomp($age);
#calculate age in days
my $age_in_days = $age*365;
print "You are $age_in_days days old in days\n";

2>

#!/usr/bin/perl
use strict;
use warnings;
my @Chandanaarray;
#initialize a 20-element integer aarray with numbers 0,...19
for(my $i=0;$i<20;$i++){
   $Chandanaarray[$i] = $i;
}

#print elements one-by-one using foreach
foreach my $eachkey (@Chandanaarray){
   print "$eachkey\n";
}

3>

use Net::Domain qw(hostname hostfqdn hostdomain);

my $host = hostname();
print "The host name is $host \n";

4>

use strict;
use warnings;
use 5.010;

use HTTP::Tiny;
use Data::Dumper qw(Dumper);

my $myDemoWebsite = 'https://www.ndtv.com//';

my $response = HTTP::Tiny->new->get($myDemoWebsite);
if ($response->{success}) {
while (my ($name, $v) = each %{$response->{headers}}) {
for my $value (ref $v eq 'ARRAY' ? @$v : $v) {
say "$name: $value";
}
}
if (length $response->{content}) {
say 'Length: ', length $response->{content};
       delete $response->{content};
}
   print "\n";
  
   print Dumper $response;
   open(my $fh, '>', 'report.txt');
   print $fh $response;
   close $fh;
   print "File Saved\n";
} else {
say "Failed: $response->{status} $response->{reasons}";
}

5>

#!/usr/bin/perl -w

use Win32::Service;


$host = '';
$status = Win32::Service::GetServices($host, \%services);

if ($status) {
LetsCServices( \%services );
} else {
print_error();
}


sub LetsCServices {
my($hash_ref) = $_[0];
@keys = keys( %$hash_ref );
@sorted = sort( @keys );
foreach $key (@sorted) {
print "$key $$hash_ref{$key}\n";
}
}

sub print_error {
print Win32::FormatMessage( Win32::GetLastError() );
}
please install win32 :: Service installed to get output in your system.

you may get warning to install the same.

Thanks,

Kindly upvote.

Chandana

Add a comment
Know the answer?
Add Answer to:
Write a perl script to accomplish following tasks: 1. Prompt user to enter their name and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is for script for terminal or putty question 1------ 1. Write a PERL script/program based...

    this is for script for terminal or putty question 1------ 1. Write a PERL script/program based on the following requirements. The program should to prompt the user for how many courses the plan to take next semester and ask the user to enter each of those courses before displaying all the information entered back on the screen. question 2------ 2. Write a PERL script that defines/declares an array or a list of elements. The array should hold three-letter abbreviations for...

  • MATLAB script 1) Prompt the user for their first name 2) Prompt the user for their...

    MATLAB script 1) Prompt the user for their first name 2) Prompt the user for their last name 3) Prompt the user for their age Display a sentence that greets the user using their first and last name, and congratulates them for what will be their age on their next birthday. Example: Hello John Smith. Congratulations on turning 45 on your next birthday!

  • 3,4,5,6,7,8 please 1. Enter the code to prompt a user to enter their name into a...

    3,4,5,6,7,8 please 1. Enter the code to prompt a user to enter their name into a script and save to name. imputl name) 2. Enter the code to display their name to the command window using "disp" function. 3. Enter the code to display their name using the "fprintf" function ame 4. What is the main difference between the "disp and "fprintf" commands? on 5. What is the main difference between the "fprintf" and "sprintf" commands? 6. What is a...

  • Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds:...

    Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds: "message and store in the weight variable. 6. Initialize an int variable named heightIn Inches to feet OſHeight times 12 plus Inches OfHeight. 7. Initialize a double variable named BMI to weight * 703.0 heightIrinches El VB 8. Initialize a double variable named ratio to height In Inches? 703.0 9. Initialize a double variable named lower Normal to 18.5 times ratio. 10. Initialize a...

  • Write a complete program in assembly line that:    1. Prompt the user to enter 10...

    Write a complete program in assembly line that:    1. Prompt the user to enter 10 numbers.    2. save those numbers in a 32-bit integer array.    3. Print the array with the same order it was entered.    3. Calculate the sum of the numbers and display it.    4. Calculate the mean of the array and display it.    5. Rotate the members in the array forward one position for        9 times. so the last...

  • 1) Write a MATLAB script to prompt a user to input two numbers, then assess whether...

    1) Write a MATLAB script to prompt a user to input two numbers, then assess whether the two numbers are equal or not. If the two numbers are equal, display that they are equal in the Command Window. If they are not equal, display that they are not equal in the Command Window. 2) Write a MATLAB script that prompts the user to enter the day of the week using the input function. If the information the user enters is...

  • 1. print mesage to user to prompt user to enter 10 numbers 2 have program accept...

    1. print mesage to user to prompt user to enter 10 numbers 2 have program accept 10 numbers from user and populate 10 occurrances of an array (use a loop to do this). 3. print message to user to advise user contents of array follows 4. have program display array contents (use loop to do this) end program comment in java please

  • In assembly language computer programming 1. create a 5 element array 2.prompt the user to enter...

    In assembly language computer programming 1. create a 5 element array 2.prompt the user to enter 5 numbers to fill the array 3. exchange the number at position 1 with the number at position 4 of the array. (Don't forget that array positions are counted from zero, in our case 5 element array positions are counted 0,1,2,3,4.) 4.Display the array numbers 1 and 4 to show that you did the exchange correctly. Show a message like "The number at position...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • 1. Write the command to set the following permissions on a script file with the following...

    1. Write the command to set the following permissions on a script file with the following name; myscript.sh Owner: full access; read, write and execute Group: read and execute Other: no access 2. Create a new file with the name "myfirstscript.sh". Write a new script that performs the following tasks in sequence; Display the usernames of currently logged in users; sorted from a-z HINT: You will need to filter the output of the whocommand Display a list of usernames who...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT