<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.3.2">
</HEAD>
<BODY>
For temp files you could use File::Temp to generate unique temp file names if you're concerned at all about overwriting or race conditions. Couldn't you just hold it in memory though? I'm not familar with the requirements of tidy.exe...does it need a file?<BR>
<BR>
Diona<BR>
<BR>
<BR>
<BR>
On Thu, 2005-04-21 at 09:23 -0400, Cory Foy wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">This is a two-in-one post question. :)</FONT>

<FONT COLOR="#000000">I am working on a little script that works with some HTML being </FONT>
<FONT COLOR="#000000">returned. Because I ultimately need to make XPath queries into it, and </FONT>
<FONT COLOR="#000000">the HTML is not XHTML, I need to tidy it up.</FONT>

<FONT COLOR="#000000">The solution I have was to get the content back, write it to a temp </FONT>
<FONT COLOR="#000000">file, make an external call to Tidy telling it to write back to the </FONT>
<FONT COLOR="#000000">file, and then re-reading in the file. It looks like:</FONT>

<FONT COLOR="#000000">####################</FONT>
<FONT COLOR="#000000">my $out = $mech-&gt;content();</FONT>
<FONT COLOR="#000000">$out =~ s/&amp;/&amp;amp;/g;</FONT>

<FONT COLOR="#000000">open TEMP, '&gt;tmp1.1';</FONT>
<FONT COLOR="#000000">print TEMP $out;</FONT>
<FONT COLOR="#000000">close TEMP;</FONT>

<FONT COLOR="#000000">`c:\\perl\\tidy.exe --write-back true --output-xhtml true c:\\perl\\tmp1.1`;</FONT>

<FONT COLOR="#000000">my $file = 'c:\\perl\\tmp1.1';</FONT>
<FONT COLOR="#000000">my $xp = XML::XPath-&gt;new(filename =&gt; $file);</FONT>
<FONT COLOR="#000000">####################</FONT>

<FONT COLOR="#000000">(by the way, I'm sure my Perl is rusty - just getting back into it after </FONT>
<FONT COLOR="#000000">a while, so syntactic suggestions are welcome too)</FONT>

<FONT COLOR="#000000">So two questions:</FONT>

<FONT COLOR="#000000">1) What is a better way to get a temp file? I don't like the hardcoding </FONT>
<FONT COLOR="#000000">of a file name - it smells to me.</FONT>

<FONT COLOR="#000000">2) Is there a better way to tidy the output so that I don't have to rely </FONT>
<FONT COLOR="#000000">on writing to a temp file which has to be processed by tidy?</FONT>

<FONT COLOR="#000000">Thanks!</FONT>

<FONT COLOR="#000000">Cory</FONT>

<FONT COLOR="#000000">_______________________________________________</FONT>
<FONT COLOR="#000000">charlotte mailing list</FONT>
<FONT COLOR="#000000"><A HREF="mailto:charlotte@pm.org">charlotte@pm.org</A></FONT>
<FONT COLOR="#000000"><A HREF="http://mail.pm.org/mailman/listinfo/charlotte">http://mail.pm.org/mailman/listinfo/charlotte</A></FONT>
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>