![]() So you can do something like: s%)% change $_ here without disturbing the running substitution %eg Once perl started substituting a string this string will not change even if you change the variable the string originally came from. However I can have my cake and eat it too because the $_ inside the body of a substitution does not have to remain the same as the $_ being substituded. $_ being two things at once seems impossible. The target string I also want to manipulate using substitutions and for the same reason I want that in $_ too. ![]() All this can be accomplished using s%)% code using $1 to distinguish %eg And I also want an easy way to distinguish. To avoid having to write $var =~ I want the control string in the perl default variable $_. I will walk the control string looking for using a substitution which is usually the shortest way in perl to process something character by character. So I'm going to swap i and I in the target string at each step so I only need to apply the rule to one letter ever. Move right if there is a space or end of string to the right.The control string alternates instructions for i and I and the rule is the same for both of them if you formulate them as: Trailing spaces or periods and a single trailing newline are optionally allowed in the output. Your program or function needs to print or return a string of the final Ii line after applying all the shifts in the order given, using spaces ( ) or periods (. Note that with these rules, I will always remain to the left of i, and I is attempted to be shifted before i for all emoticons. I cannot be shifted left if I is directly to its left (as it is initially), but can always be shifted right. I cannot be shifted left if it is at the left edge of the line (as it is initially), and cannot be shifted right if i is directly to its right (as it is initially). _ shifts I to the left by one, if possible, and then shifts i to the right by one.>_> shifts I to the right by one, if possible, and then shifts i to the right by one. ![]() Write a program or function that takes in a string of an arbitrary list of these four ASCII emoticons, either space or newline separated (with an optional trailing newline): >_>Įach emoticon performs a different action on the I and i characters, which always start like this: Ii Given a string of shifty-guys, spaced apart or separate lines, shift the Ii's side to side, left the wall and right the skies: Ii Shifty-eyes ASCII guys like to shift ASCII Ii's: >_> _ ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |