Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Is there a module for object-oriented substring handling/substitution?

by LanX (Canon)
on Jan 26, 2013 at 20:31 UTC ( #1015535=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Is there a module for object-oriented substring handling/substitution?
in thread Is there a module for object-oriented substring handling/substitution?

OK now with the knowledge of your use case, I'd rather recommend to work with a document tree representing your wiki page as a hash of hashes.

Much like a DOM-tree, you could traverse it for whatever markup-element ("table") you want.

Parse the wiki-page into a tree, manipulate the tree and rebuild the page again.

Otherwise:

If you insist to stick persistent meta-informations to ranges of characters, then you should better work with arrays of characters. You could tie or bless the scalar elements with whatever info you want. If your user inserts or deletes anything from the array your metainfos will move accordingly.

And if you wanna go the full "emacs way" you need to realize linked lists. The easiest way is having 2 element arrays  [$value,$successor_ref]

EDIT:

After some meditation, IMHO if you need full interactivity, better stay with the AoH with the document tree, and a "cursor" pointing to the current element. Whenever the user does insert characters update the tree at the point the cursor points to.

You'll also need to store informations like "parent", "child", "nextSibling" ...

Have a look at DOM or XML modules at CPAN for inspiration.

Cheers Rolf


Comment on Re^3: Is there a module for object-oriented substring handling/substitution?
Download Code
Re^4: Is there a module for object-oriented substring handling/substitution?
by smls (Friar) on Jan 26, 2013 at 21:54 UTC

    I seemed to have caused some confusion with my previous post (sorry about that):

    When I wrote about playing nice with page edits by humans, I did not mean actual interactivity while the script is running.
    The script performs a self-contained, non-interactive operation: Pull the page source into a string, update specific values, submit the updated page source back to the server, exit.
    The human editing happens in between multiple such runs of the script, on the wiki itself.

      > I did not mean actual interactivity while the script is running.

      So my first statement still holds, you need to parse the content into a tree, manipulate some nodes and export again as markup.

      Wiki-syntax is nested, e.g. a table entry can be bold or a link!

      No "object-oriented substrings" needed!

      Cheers Rolf

        But then I could not guarantee that the output is exactly the same as the input outside of the specific values being updated.

        DOM-tree<-->wiki-syntax is a one-to-many relationship, for example each of the following is a valid wiki-syntax representation of a table row containing 3 cells with the contents A, B, and C:

        |- | A || B || C

        |- | A | B | C

        <tr> <td>A</td> <td>B</td> <td>C</td> </tr>

        Also, I doubt that writing a full-blown parser and serializer would result in less work and less code than a regex-based solutions supported by linked substrings.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-08-28 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (257 votes), past polls