Saturday, 15 February 2014

substring - Scramble a string Perl -


I am using an object and reverse to scramble a string. But my solution was difficult to write and there should be a very easy way. Should it be able to work with only two variables allegedly substrings and reverse? but how? The substrings only removes the letters that I want, and abandons the remaining string. Appreciate any input.

  #! / Usr / bin / perl $ string = mystring; $ Name = substr ($ string, 0, 2); $ Name = reverse ($ name); $ Name1 = substr ($ string, 2, 4); $ Name2 = substr ($ string, 6, 8); $ Name2 = reverse ($ name2); Print UK ($ name); Print uc ($ name1); Print uc ($ name2);  

You can use the function from

  Strict use; Use warnings; Usage list :: UTL QW (shuffle); My $ string = 'mystring'; My $ shuffled_string = join '', shuffle (split //, $ string); # 'Nmyisgrt'  

No comments:

Post a Comment