On Tue, Jun 07, 2005 at 08:23:43AM -0700, Bryan R Harris wrote:
>
> >>> Any ideas?
> >>
> >> Wrap the use() statement in an if block.
> >>
> >> if ( $^O eq 'darwin' ) {
> >> use POSIX;
> >> } else {
> >> use POSIX qw(:sys_wait_h);
> >> }
> >>
> >> Will that work?
No.
> > Only if you wrap that in a BEGIN block.
And not even then.
> > Remember, 'use' happens at
> > compile not run time.
This is true, but BEGIN happens at compile time too so you've not gained
much.
> Here's what I tried:
>
> **************************************
> BEGIN {
> if ( $^O eq 'darwin' ) { use POSIX; }
> else { use POSIX qw(setsid nice :sys_wait_h); } # line 14
> }
>
> ... but it still errors out:
> Any other ideas?
"perldoc -f use" reminds us that "use Module LIST" is exactly
equivalent to
BEGIN { require Module; import Module LIST; }
so:
BEGIN
{
require POSIX;
POSIX->import($^O ne "darwin" ? qw(setsid nice :sys_wait_h) : ())
}
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>