Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: My first JAPH

by teamster_jr (Curate)
on Mar 18, 2004 at 11:42 UTC ( [id://337660]=note: print w/replies, xml ) Need Help??


in reply to My first JAPH

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:
I've dropped $J and $h - and rolled it all into a single routine:
$_="jsreutPJpl";s/$&/$p=pos/e;
and @j and a foreach loop is replaced with a regex.
The part that adds the . is moved out of the loop and moved to a regex.
al

Replies are listed 'Best First'.
Re: Re: My first JAPH
by muba (Priest) on Mar 19, 2004 at 17:49 UTC
    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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://337660]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found