<?xml version="1.0" encoding="windows-1252"?>
<node id="989563" title="Re^3: how to output file in Unicode" created="2012-08-24 10:57:34" updated="2012-08-24 10:57:34">
<type id="11">
note</type>
<author id="989386">
philiprbrenan</author>
<data>
<field name="doctext">
&lt;code&gt;
sub writeUnicode($$)
 {my ($f, $s) = @_;
&lt;/code&gt;
&lt;p&gt;Assigns parameter 1 to the subroutine from @_ to $f and parameter 2 to $s.  One could also write my $f = $_[0]; my $s = $_[1];
&lt;/p&gt;
&lt;code&gt;
  if ($f =~ /\A(.+[\\\/])/)
   {my $d = $1;
    makePath($d);
   }
&lt;/code&gt;
&lt;p&gt;Extracts the path component of the file name and places it in variable $d so that we can make a directory for the output file.  If you know that the output directory exists, then there is no need for this code. The assignment to $d is somewhat verbose, one could use makePath($1) to use the first expression captured by the regular expression in the if statement directly. The regular expression captures the text up to the last \ or / in the file name and uses that as the path component.&lt;/p&gt;
&lt;code&gt;
  say {$F} $s;
&lt;/code&gt;
&lt;p&gt;Writes the contents of $s to the file whose handle is in $F.  The file is automatically closed at the end of the block containing my $F.  This statement is an alternative to $F-&gt;say($s);
&lt;p&gt;
</field>
<field name="root_node">
989377</field>
<field name="parent_node">
989453</field>
</data>
</node>
