I'm now thinking this is some sort of bug.
Try running the following two programs below to see what I mean.


###############################################
# --perl-- First Program using 'use'

# This should sound like a skipping record album.
# Pick a relatively long wavefile to play >3 or 4 seconds

use Win32::Sound;

$wavefile="C:/windows/media/themic~1.wav";

for($i=0;$i<=4;$i++){
        Win32::Sound::Play($wavefile,SND_ASYNC);
        sleep(1);
}
__END__ 

###############################################

# --perl -- Second Program using 'require' and 'import'
# This should also sound like a skipping record album, 
# but does not..well, it doesn't for me, anyway.
# Pick a relatively long wavefile to play >3 or 4 seconds

BEGIN:{
        if ($^O eq "MSWin32"){
                require Win32::Sound;
                eval( Win32::Sound->import(qw(SND_ASYNC)) );
        }
        else(
                exit;
        )
}## end BEGIN block

$wavefile="C:/windows/media/themic~1.wav";

for($i=0;$i<=4;$i++){
        Win32::Sound::Play($wavefile,SND_ASYNC);
        sleep(1);
}
__END__







-----Original Message-----
From: Jan Dubois [mailto:[EMAIL PROTECTED]]
Sent: May 1, 2000 6:39 PM
To: Jack Dunnigan
Cc: Perl-Win32-Users Mailing List
Subject: Re: use Win32::Sound


On Sat, 29 Apr 2000 13:34:34, "Jack Dunnigan" <[EMAIL PROTECTED]>
wrote:

>But I know of no way to include a 'use' statement under a conditional
statement.

You have to put the conditional in a begin block, like this:


    BEGIN {
        if ($condition) {
            require Module;
            local $@;
            eval { Module->import() };
            # or if you want to import only specific names:
            # eval { Module->import(qw(NAME1 NAME2 $VAR1 $VAR2)) };
        }
    }

The eval is necessary because the absence of an import() method should not
be an error (at least the implementation of "use" things so).

-Jan

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to