in reply to Re: My first JAPH
in thread My first JAPH

Hmm... I don't really understand what's going on here.
According to perldoc -f pos, pos returns a number. Then, you replace the last succesful match ($&, which is just any character but \n (.)) with a number ($p (= pos (= pos $_))).

Then comes the part of adding the dots. It's a way I'd never thought of, but it's easy to understand.

But I really don't get the part with the one regexp within the other. I just don't get how that pos thingy can actually generate the number the script needs.

Replies are listed 'Best First'.
Re: Re: Re: My first JAPH
by teamster_jr (Curate) on Mar 20, 2004 at 15:01 UTC
    Hi Muba,

    in your original you have this:

    foreach$h(split//,"JussJsstssPerlJssjsssssPsjusjsssuerpjsjsssusjpersjulJllsjJ" (etc).

    So the char that you're matching (which you change into a number based on its position within the jsreutPJpl string) is in $h

    What i did was replace the foreach loop with a regex:
    $_=<long string here>;s^.^<the code from the foreach loop here>^eg

    So now instead of in $h the character from the long string, which is being matched is in $&.

    so what this: $_="jsreutPJpl";s/$&/$p=pos/e; does is find the char from the long string within the short string.

    pos returns to position of the match within the short string. set $p to this and return it into the long string regex substitution - so now in the long string each character has been replaced by it's position in the short string - ready for adding dots...

    hth.
    alex

      Ah, I get the basics now. Wow, that's really, eh, cool!