Re: Linux question

new topic     » goto parent     » topic index » view thread      » older message » newer message

You could do it like this:

function getrandfilename()
    integer r1,r2,r3,limit
    limit=1000000    -- some big number
    r1=rand(limit)
    r2=rand(limit)
    r3=rand(limit)
    return sprintf("%s",r1) & "." & sprintf("%s",r2) & "." & 
sprintf("%s",r3) & ".tmp"
    -- the filename would be a filename like '65783.999070.12.tmp'
    -- the odds of creating a duplicate would be 1/limit^3   (very very 
slim)
    -- The '.' between each number is totally unnecessary.
end function

sequence myfile
myfile = getrandfilename()

I've been doing something like this in a program of mine to create unique 
filenames, and it has worked perfectly well.  I guess there's always a 
chance of a duplicate, but there's a chance I'll win the Powerball lottery 
too.  Neither chance keeps me up at night.

Or, maybe you could do it with just Linux commands:
system_exec("declare -x `myprogXXXXXX`",0)

NOTE: In the command above, the single tics are back-tics (the one on the 
same key as the tilde key, next to the 1 key).   This command will create 
an environment variable  in RAM with the same name as the temp file it 
creates.  You can't use the '.' character in the name, but hey, you don't 
really need to, anyway...  Then just read the enviroment variable and 
you've got your name...Some procedure using that might work for you.  The 
declared variable won't persist between shell sessions, though.

Using the back-tics are one of the coolest shell features of Unix, I 
think... :)

--Ted

--On Saturday, April 21, 2001 08:29:54 AM -0500 Irv Mullins 
<irvm at ellijay.com> wrote:

>
>
>
> I need to create unique temporary files, which I can do using
> mktemp , i.e. system_exec('mktemp myprog.XXXXXX',0)
>
> The question is, how do I find out what name mktemp has used
> to create my file? The name is normally printed on the console,
> and I don't kow how to redirect that so Euphoria can get to it.
>
> Thanks,
> Irv
>
>
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu