Question: Write a program that writes a string Perl is cool! to a file as follows: 1. First, ask the user to input the name of

Write a program that writes a string "Perl is cool!" to a file as follows:

1. First, ask the user to input the name of the file to write the string to.

2. If the input file exists, check if there is a subdirectory named "backup". If there is, print "Checking backup directory... already exists", if not, create the "backup" subdirectory and print "Checking backup directory... backup directory created". Note: You can create a new directory using mkdir function.

If the input file exists and the file has more than 10 lines, give the user 2 choices:

Type 'c' to copy first 10 lines of the file under "backup" folder with the same name, and then overwrite the existing file

Type 'o' to proceed without creating a backup, and overwrite the existing file

If the input file exists and it has not more than 10 lines, backup everything under the "backup" folder with the same name, and overwrite the existing file. Note: Copying should be performed with Perl's file read/write functions, rather than using the operating system's file operations functionality.

Oherwise, write the string to the input file normally.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!