On 22Jul2006 12:54, Michael Sullivan <[EMAIL PROTECTED]> wrote:
| I'm trying to create a mail filter script in perl.  The user will send
| mail to the script and the script will hold the mail until it receives
| further orders from the script.  Each individual email needs to be
| stored in its own file while waiting to be processed.  I want a random
| code for the filename to be used for each individual email.  I was
| thinking something like this:
| 
| date +%N | md5sum
| 
| However, while I can call this command using exec(), how do I use the
| output in my script?

Like this:

    $code = `date +%N | md5sum`;        # collect output of shell command
    chomp($code);                       # trim the trailing newline

However, a few remarks:

  - %N is nanoseconds, but on most systems it is not so precise.
    Try "%s.%N", or even "%s.%N.$$" (note the double quotes - we're
    relying on the shell replacing $$ with the process id here).

  - MD5 is a one-way hash. So the output of MD5sum is inherently _smaller_
    than the possible inputs. So you're better off just using the output
    of the date command unless there is some consideration you have not
    mentioned.

  - Running a shell command to do this is pretty slow. In fact, REALLY
    REALLY slow. You are only getting the current time and (needlessly)
    performing a hash computation on it. Compared to the work involved in
    forking processes, firing up new commands (loading from disc if
    not cached, linking shared libraries, rewriting process address spaces)
    it's a tiny amount of work, grossly smaller that the new process
    overhead.
    It's only worth doing that work if it's hard to do the job inside
    perl.
    Consider this:

      $code = time+".$$";       # time in seconds plus process id

    It should be sufficiently unique, and it's quite fast.

Cheers,
--
Cameron Simpson <[EMAIL PROTECTED]> DoD#743
http://www.cskk.ezoshosting.com/cs/

It's there as a sop to former Ada programmers.  :-)
        - Larry Wall regarding 10_000_000 in <[EMAIL PROTECTED]>


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/XISQkA/lOaOAA/yQLSAA/0XFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe from this list, please email [EMAIL PROTECTED] & you will be 
removed. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/LINUX_Newbies/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to