mIRC Home    About    Download    Register    News    Help

Print Thread
#256052 14/12/15 06:13 PM
Joined: May 2014
Posts: 36
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 36
Hello, you can tell me, if it is possible to turn a string. for example in uppercase lowercase left and right I know, but I am looking for a handle that allows me to read upside down. for example:

$get...(Hello)
with result: olleH

it's posible?? . greetings and sorry for my bad English

Perl #256053 14/12/15 06:36 PM
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
There is probably some better way to do it, but this works too:
Code:
alias reverse var %x = 1,%r | while ($mid($1,%x,1) != $null) { var %r = $+($v1,%r) | inc %x } | return %r


Use as: $reverse(Hello world!)


EDIT:
Even better and faster alternative:
Code:
alias reverse return $regsubex($1,/(.)/g,$mid(\A,-\n,1))

Last edited by Dazuz; 14/12/15 06:44 PM. Reason: Another brain fart.
Dazuz #256055 14/12/15 10:03 PM
Joined: May 2014
Posts: 36
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 36
Dazuz you're a machine!! the only problem I see is the text that leads commas, which cuts right where they are. Thank you!! $reverse(hello, my name) -> olleh
I will try to fix it !!
thank iu!!

Perl #256056 14/12/15 10:15 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
store the text in a variable prior to calling the alias:
Code:
var %input = hello, my name is jim
echo -a $reverse(%input)


I am SReject
My Stuff
Joined: May 2014
Posts: 36
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 36
Now if it works, greetings and thank you very much.

Dazuz #256074 16/12/15 04:04 PM
Joined: May 2014
Posts: 36
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 36
also it seems to have tried putting $1- , and it seems that also works unused variable.


Quote:
alias reverse return $regsubex($1-,/(.)/g,$mid(\A,-\n,1))


but I think your choice is better, thanks

by the way, I'm trying to understand the code and see very complex, I will have to study it calmly. Cheers

Last edited by Perl; 16/12/15 04:12 PM.
Perl #256075 16/12/15 04:45 PM
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
The commas separate the input into different parts in identifiers. With $1- it'll read all the parts, but the commas will also be removed, since they're considered separators.

The commas are only a problem if you define the input manually, i.e. $reverse(Hello, world and, stuff!), so using the identifier in text event/alias/whatever where the input comes from the user/whatever, i.e. $reverse($1-) or $reverse(%variable), won't be a problem.

The $regsubex version works pretty much exactly the same as the while loop one, except it's more efficient. It's probably easier to break the while loop one into parts and study it, you'll get the same result, except it's probably easier to understand, tweak and play around with.


EDIT:
I'm bored, so:
Code:
;Start of the alias called "reverse".
alias reverse {

  ;Set local variable %x to 1 and unset %r.
  var %x = 1,%r

  ;Loop, which continues as long as $mid returns something.
  ;$1 being the input, %x being the position and 1 being the amount of characters $mid is allowed to return at once.
  ;It literally goes character by character the given input until it reaches the end, which is $null.
  while ($mid($1,%x,1) != $null) {

    ;Set local variable %r to whatever $mid returned in the loop above ($v1), and attach it to the left side of whatever is in %r, if there is anything.
    var %r = $+($v1,%r)

    ;Increase %x by 1.
    inc %x
  }

  ;Return the result.
  return %r
}

Last edited by Dazuz; 16/12/15 04:57 PM. Reason: Boredom strikes!
Dazuz #256076 16/12/15 05:29 PM
Joined: May 2014
Posts: 36
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 36
Thanks, I was interested to learn, I appreciate it very much, it is very important for me to understand what they do codes. a greeting


pd: with your explanation, I understand better now if you like it does :)) thank !!

Last edited by Perl; 16/12/15 05:31 PM.

Link Copied to Clipboard