Create a file that has a series of ten strings in it, all accepted from the user through the keyboard. Then, open that file in read mode, and reverse the order of the characters in each line, saving the reversed line to a new file. Display the completed reversed file when done.
Need help this done in PERL language. Thank you
Your required answer for the above problems is below -
Code -
# Opening file Hello.txt in write mode open (fh, ">", "File1.txt"); for ($i = 0; $i < 10; $i++) { # Getting the string to be written # to the file from the user print "Enter the content to be added\n"; $a = <>; # Writing to the file print fh $a; } # Closing the file close(fh) or "Couldn't close the file"; # open File1 to read open (FHR, "<", "File1.txt"); # open File2 for writing open(FHW, '>', "File2.txt"); while(<FHR>) { print FHW scalar reverse("$_"); } # Closing the filehandles close(FHR); close(FHW); print "File content copied successfully!\n";
Output -
Input from user
File1 strings from user
Reverse order string from File1
Note :- I have commented wherever it is required to make you understand the program, still you find any difficulty in understanding anything in the program then let me know. If you are happy with my response then please give positive feedback. Thanks
Get Answers For Free
Most questions answered within 1 hours.