<?xml version="1.0" encoding="windows-1252"?>
<node id="735081" title="Re: TIMTOWTDI Challenge: Create a filename" created="2009-01-09 00:13:23" updated="2009-01-09 00:13:23">
<type id="11">
note</type>
<author id="268515">
xdg</author>
<data>
<field name="doctext">
&lt;p&gt;Assuming a quick-and-dirty temporary filename is desired:
&lt;/p&gt;

&lt;c&gt;
my $filename = int rand 2**31;
&lt;/c&gt;

&lt;p&gt;Or pick a large random number of your choice.  Plus if you need to generate the *same* temporary filenames on successive runs, you can set the seed for rand() ahead of time.&lt;/p&gt;

&lt;p&gt;Similar in nature, but random alphanumerics, not unlike what File::Temp does internally:&lt;/p&gt;

&lt;c&gt;
my @chars = ('a' .. 'z', 'A' .. 'Z'); 
my $filename = join("", map { $chars[int rand(0+@chars)] } 0 .. 7);
&lt;/c&gt;


&lt;div class="pmsig"&gt;&lt;div class="pmsig-268515"&gt;
&lt;p&gt;-xdg&lt;/p&gt;
&lt;p&gt;&lt;small&gt;&lt;i&gt;Code written by xdg and posted on PerlMonks is [http://creativecommons.org/licenses/publicdomain|public domain]. It is provided &lt;b&gt;as is&lt;/b&gt; with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.&lt;/i&gt;&lt;/small&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
735007</field>
<field name="parent_node">
735007</field>
</data>
</node>
