I've got my first JAPH finished. What do you think about it? Can I make it any shorter? Can I do it better?
BTW, It's not too difficult to hack, I think.
Please let me know if you found out how it works :)
Anyhow, it even works with 'use warnings' and 'use strict':
our(@j,$a,$p,$h,$J);print do{@j=split//,"233322333333223332322333";$a= +"";$p=0; foreach$h(split//,"JussJsstssPerlJssjsssssPsjusjsssuerpjsjsssusjpersju +lJllsjJ". "sjsssu"){$J=0;foreach(split//,"jsreutPJpl"){if($_ eq $h){last}$J++}$p +++;$a.=$J ;if($p==$j[0]&&$#j!=0){$a.=".";shift@j;$p=0}}eval$a}.$/;

Replies are listed 'Best First'.
Re: My first JAPH
by teamster_jr (Curate) on Mar 18, 2004 at 11:42 UTC
    how's this? it works using the routines as yours, just written differently - and it should still work under strict and warnings..
    $_="JussJsstssPerlJssjsssssPsjusjsssuerpjsjsssusjpersjulJllsjJsjsssu"; +my ($a,$p);print do{s^.^$_="jsreutPJpl";s/$&/$p=pos/e;$p^eg;for$p(split// +," 23332233333322333232233"){$a+=$p;s#.{$a}#$&.#;$a++}eval}.$/
    there's a spoiler here:
    al
      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.
        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