Reverse String Word by Word

Problem

Write a program to reverse an English sentence word by word not character by character. For example if the sentence is “I love Pizza so much” the program should print “much so Pizza love I”

Solution

One solution is to split the sentence into tokens using the space character as the separator then print the tokens in reverse order

Code

Here is how to do that in Perl

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *