Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

Im pretty new to perl, but come from a C background and am wondering is it possible to pass a struct {} address to a syscall (using the syscall() wrapper that perl provides, for example, to call nanosleep()).

I was just after a way to pause a threads execution for less than a second in a simple script, and have found myself dealving more and more into this awsome language. ;D

Looks like im hooked.

Replies are listed 'Best First'.
Re: syscall() struct problem.
by Corion (Patriarch) on Mar 29, 2006 at 18:38 UTC

    If you just want a subsecond sleep, there are two ways that don't involve syscall():

    use Time::Hires; - that transforms the plain sleep call into a sleep call that understands fractions of seconds.

    Use the four argument version of select as

    select(undef, undef, undef, 0.25);

    to sleep for 0.25 seconds

    If you're bent on using syscall(), the pack (and unpack) function will become your best friends, as these allow you to create binary structures and pointers to them. pack has all about it.

      I'd just like to add this:

      The pack templates you're after are "p" and "P", which produce a pointer in a packed integer (much like "L").

      Make sure you don't change the scalar you're pointing to between pack and syscall, or that scalar might move, and the pointer will point somewhere invalid.