Question

Write a perl program Use a while loop to get user input until the user enters...

  • Write a perl program
    • Use a while loop to get user input until the user enters "quit"
    • Use a regex to replace any occurrence of the word "python" with the word "perl" and print out the updated version
  • Provide the perl program (.pl file) as well as a screenshot of the output (show at least one example with python being replaced)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Perl Program:

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

# Declaring variable
my $txt;

# Prompting user
print("Enter some text, (Type quit to exit).\n");   
# Reading input from user
chomp($txt = <STDIN>);   

# Loop till user enters quit
while($txt ne "quit") {
# Changing to lower case
$txt = lc($txt);
# Printing to user
print("\nYou entered:$txt\n");
# Replacing string
my $modified = $txt =~ s/python/perl/r;
# Printing modified string
print("\nModified as:$modified\n");
# Prompting user
print("\n\nEnter some text, (Type quit to exit).\n");   
# Reading input from user
chomp($txt = <STDIN>);   
}

_____________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
Write a perl program Use a while loop to get user input until the user enters...
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
  • Write a Perl program that prompts a use to input a line of text. If the...

    Write a Perl program that prompts a use to input a line of text. If the line of text has a word that is capitalized but not ALL capitalized, the program outputs “FOUND.” Otherwise, it outputs “NOT FOUND”. For example, if the user enters “Fred,” the program outputs “FOUND.” But if the user enters “fred” or “FRED,” the program outputs “NOT FOUND.”

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • Write a Perl program that prompts a use to input a line of text. If the line of text mentions bot...

    Write a Perl program that prompts a use to input a line of text. If the line of text mentions both John and Smith, the program outputs “FOUND.” Otherwise, it outputs “NOT FOUND.” Write a Perl program that prompts a use to input a line of text. If the line of text has a word that is capitalized but not ALL capitalized, the program outputs “FOUND.” Otherwise, it outputs “NOT FOUND”. For example, if the user enters “Fred,” the program...

  • Write a Python program that keeps reading in names from the user, until the user enters...

    Write a Python program that keeps reading in names from the user, until the user enters 0. Once the user enters 0, you should print out all the information that was entered by the user. Use this case to test your program: Input: John Marcel Daisy Samantha Nelson Deborah 0 ================ Output: John Marcel Daisy 25 Samantha Nelson Deborah Hints: Create an array Names to hold the input names. Use the Names.append(x) function to add a new name to the...

  • Write a PYTHON program that reads a file (prompt user for the input file name) containing...

    Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1   0.5 2   0.5 3   0.5 4   0.5 The output should be:    The averages are 2.50 and 0.5. a)   Your code with comments b)   A screenshot of the execution Version 3.7.2

  • IN PERL Write a program that will ask the user for a number and will print...

    IN PERL Write a program that will ask the user for a number and will print all the integers in order starting from 1 until the number. Use the <> operator to ask for the user's input. For this program you will write a countdown timer. Your time will count down from 1 minute (60 seconds) to 0. Once the timer gets to 0 seconds the system will display a message that reads: RING RING RING! -using do while-

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • Write a piece of code that enters a loop and asks the user to input anon-negative...

    Write a piece of code that enters a loop and asks the user to input anon-negative number. If the user enters a negative number, the code goes back into the loop and asks the user again to enter a non-negative number. The code keeps going back into the loop until the user enters a non-negative number. Notice that the code enters the loop at least once. This is an application of 1 to N loop.Therefore, use a Do While statement.

  • Perl Write a program with a subroutine that keeps prompting for a filename until a valid...

    Perl Write a program with a subroutine that keeps prompting for a filename until a valid file is entered by the user (print out "file found, thanks") or until five attempts have failed (print out "you did not enter a valid file name"). The sub in this case does not return any value.

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