Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to do a blocking readdir or similar

by merlyn (Sage)
on Dec 19, 2005 at 03:12 UTC ( [id://517657]=note: print w/replies, xml ) Need Help??


in reply to How to do a blocking readdir or similar

POSIX doesn't provide such a hook, so most unix-like systems also don't have such a hook. Your solution of polling is probably the best portable solution.

However, if you're smart enough with AppleScript, you can attach an applescript action to a folder drop, which can then launch your Perl program. I'm not that smart, or I'd point you at a ready solution.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on Re: How to do a blocking readdir or similar

Replies are listed 'Best First'.
Re^2: How to do a blocking readdir or similar
by saintmike (Vicar) on Dec 19, 2005 at 04:08 UTC
    POSIX doesn't provide such a hook, so most unix-like systems also don't have such a hook
    Actually, Linux provides such a hook. Check out SGI::FAM for using the file alteration monitor based on dnotify or Linux::Inotify2 for newer kernels.

      OS X (which the OP was using) shares more with FreeBSD than Linux, so IO::KQueue is probably a more appropriate choice.

      From the README...

      This module is a low level interface to the FreeBSD and Mac OS X kqueue() system call. This is basically equivalent to epoll() on Linux - a high performance poll() replacement.

          --k.


      SGI::FAM seems like a more compatible and less linux-only solution, and fam should run on Mac Os X (and BSDs of all stripes really, as it can be compiled to run with kqueue

      Update: Maybe that is not such a good recommendation, SGI::FAM depends on deprecated File::PathConvert, has an unregistered dependency on Test::Helper and doesn't find my libfam without help.
      After that, it does seem to work, though, quite well, though only on famd started as a daemon, not running through inetd.
Re^2: How to do a blocking readdir or similar
by GrandFather (Saint) on Dec 19, 2005 at 03:27 UTC

    That's not smartness, just knowledge. :)


    DWIM is Perl's answer to Gödel
Re^2: How to do a blocking readdir or similar
by brian_d_foy (Abbot) on Dec 19, 2005 at 13:26 UTC

    I describe the Mac side of the process in Automatically Import Images into iPhoto. To launch a Perl script, just call it from the AppleScript that the folder action wants.

    It sounds like the poster will have an annoying little synchronization problem though: the AppleScript creates a semaphore somehow, and the sleeping, blocking script has to check for that. Perhaps the two scripts could talk to each other in some other way, though.

    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://517657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found