Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I guess you are talking about Careful Evaluation. That one did set $_ within each eval().

It's not exactly the same here. The program is loosely inspired from my little PostScript experience. It has a stack, and spents most of its time working with it.

@_ (aliased to @ARGV, so that pop() works the way I want) is my stack. I store the data on the bottom of the stack, and the code on top of it. Each line of code is followed by a pop() that put the next line of code in the program counter (sort of). This is not the same as assigning to $_. In fact, $_ is only assigned the value of the result of the last instruction (a pop() on an empty @_: nothing).

To understand the program you have to read the stack (er, @_) backwards.

The first commands put a pop() command at the end of each element (including the data, oops), to ensure that the program will run smoothly.

Next, the hexadecimal data (except the ;pop at the end of it, thanks to substr()) is converted into characters. (OK, this part of the program uses $_ instead of the stack.)

The data is then split, converted into numbers (and negative ones, too, because these are considered signed characters) and shifted back in the bottom of the stack.

Now, the loop is constructed by repeating the two commands on top of the stack 24 times (and the print() goes first). The first piece of data is converted and printed (chr 74 is a J). The next command takes the first two bits of data, add them and put the result twice on the stack. And we loop. print(), keep the result, and add it to the next data.

By now, you found out that the hexadecimal data is the list of offset between the characters of the infamous JAPH line.

The last print() command gives the \n, and the last two pop() clean up the stack (@_) and $_.

Maybe not as easy as you first thought ($s remains the same during the whole program, and $_ is changed several times, without having its content evaluated).


In reply to 59 /e explained by BooK
in thread 59 /e by BooK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2023-02-07 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (38 votes). Check out past polls.

    Notices?