emilford has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to setup a page on my website that is basically a journal system that manages my entries. I have the page split into two parts, one containing the most recent entry and the other containing links to previous entries. I was planning on storing the entries in seperate folders by month, so that I could write a perl script to grab all of the files in a certain directory and then create links to them. That's the easy part.

The second part of what I am trying to do involves dynamically updating parts of the page. I want the user to be able to click one of the side links and have the entry that he/she clicked overwrite the text for the current post. I know how to do update dynamically using Javascript, but is it possible to use perl to grab the text contained within the specific file? Somehow pass the contents back to the Javascript?

Also, I was only planning on having the posts for the current month being shown in the menu with links back to the past two months as well. What I want to happen is that when the user clicks on a certain month, the script will grab the files in that month's directory and display links to them. Is there a way for Perl and javascript to interact to accomplish this or would I be better of just using perl and refreshing the page automatically?

If this is the case, what would be the best way to pass hidden parameters to the perl script that won't appear in the URL. I only want www.abc.com/index.pl?node=xxx to show up as the url.

Thanks

Replies are listed 'Best First'.
Re: dynamic update javascript & perl?
by Thelonius (Priest) on Dec 27, 2002 at 20:57 UTC
    You may want to have a look at OpenThought. It's a Perl module (and framework) that lets you do the kind of things you're wanting. I haven't used it yet, but I gave it a good look-over, and here are my notes on what it does:

    OpenThought allows a web page to be incrementally updated with data from the server. You can change fields on a form, e.g., without sending a whole new page.

    How OpenThought works:

    1. Instead of creating a page, you create a frameset with a parent frame, an invisible communication frame and the content frame.

    2. In the content frame, you can do anything you would normally do with a normal page. In addition, to use OpenThought, you can add JavaScript calls for any event, e.g. onclick="parent.CallUrl('anopenthoughturl', form_element, ...)"

      The javascript function CallUrl in the parent frame serializes the data from the call and sends an HTTP request to an OpenThought application at the specified URL, with the communications frame given as the target for the HTTP response.

    3. The OpenThought application deserializes the data into a Perl data structure. The application can them perform any computation. It then creates instructions to modify the content frame. OpenThought transforms these to javascript and returns the results wrapped in <script></script> tags.

    4. When the communication frame receives the complete page, it executes the script, which constructs a javascript data structure, then calls a function in the parent frame. This function uses the data structure to update the document in the content frame.
    It's easier to use than this might suggest.
      I couldn't have said it better myself :-)

      As a heads up, apparently some of the tests in version 0.63 of OpenThought don't work as they should. So there may be issues with the 'make test' phase of the installation. Corrections to this are currently being put in CVS, and will (theoretically) work correctly in the next release.

      Good luck!
      -Eric

      --
      Lucy: "What happens if you practice the piano for 20 years and then end up not being rich and famous?"
      Schroeder: "The joy is in the playing."
Re: dynamic update javascript & perl?
by hardburn (Abbot) on Dec 27, 2002 at 19:18 UTC

    I know how to do update dynamically using Javascript, but is it possible to use perl to grab the text contained within the specific file? Somehow pass the contents back to the Javascript?

    Sure, but it takes a bit of hackery to get it working. Look at XML HTTP Request objects (external link). The XML is only used on the client side, so your CGI program won't need to parse the XML. IIRC, the CGI doesn't have to do anything special beyond what CGIs already do. The hoop-jumping happens on the client side.

    Alternatively, you can have a tiny IFRAME that is refreshed by JavaScript and the text grabed out of that. This will probably work on more browsers than the XML Request, though I find it more asethetically pleasing than the IFRAME method.

Re: dynamic update javascript & perl?
by FamousLongAgo (Friar) on Dec 27, 2002 at 19:45 UTC
    What you are describing sounds a lot like a weblog — you might want to look at Movable Type, which is a Perl-written blog that is powerful, easy to configure and ( very important ) easy to hack. It's the usual dilemma about what is faster - writing what you want from scratch, or learning something new and adapting it.