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

Monks ~

I'm developing a web site using templates. Some time ago I created a small script to parse a template file, suck up all the template VARiables and IFs, and spit them out into a nicely formatted template assignment, kinda like this:

$template->param( THIS_IS_A_LONG_VARIABLE_NAME => , ANOTHER => , YOU_GET_THE_IDEA => );
This makes it very easy to (a) make sure I get all the template variables the first pass, and (b) paste this block into the script and fill in the blanks. I'm using a format to make sure the "=> ," lines up correctly, which makes it easier to read and edit.

Today I decided that the whole operation just took too damn long, so I've been fiddling with the Win32::Clipboard (won't work in Debian, sadly ;). It all works nicely except for the format, because I'm ".=" assigning to a variable, then setting the clipboard to that variable. I figure I have two options:

  1. Parse everything before assignment, figure out the longest line, pad all the other lines. *Ick*
  2. Write the format to a variable (or a variable pretending to be a filehandle) instead of a filehandle.
That's where I'm stuck. The second option is much cleaner, assuming it's possible. Ideas anyone?

Thanks!

P.S. For those who haven't used Win32::Clipboard, it's pretty simple. Here's the code that does stuff:

$clipboard = Win32::Clipboard(); $clipboard->Set( $temp );

Replies are listed 'Best First'.
Re: 'WRITE'ing a format to a scalar
by runrig (Abbot) on Aug 03, 2001 at 20:08 UTC
      Thanks, runrig. Looks like that might do the trick.

      I'm kind of new here, so please enlighten me: how could I have been more clear that I actually did mean "write" and "format?"
      --
      man with no legs, inc.

Re: 'WRITE'ing a format to a scalar
by John M. Dlugosz (Monsignor) on Aug 03, 2001 at 20:38 UTC
    use can use tie to make a filehandle point to a string instead of a file, if that's what you were wondering.
      Thanks John. I've not yet been initiated into the mysteries of "tie." Looks this this is a good time to start.
      --
      man with no legs, inc.
        That's very interesting. I had supposed that the machinary behind write eventually called PRINT or WRITE methods, but it doesn't.

        It looks like tieing file handles is still incomplete.

        —John