how to write non-compatible perl scripts to run on differnet
how to write non-compatible perl scripts to run on differnet
am 27.11.2007 13:10:45 von Torben
Hi to all,
is it possible to make some kind of pragmas in perl scripts, so for
example I can run a perl script like this:
__BEGIN__
#use Win32::Sound;
Win32::Sound::Play("SystemExclamation");
print "sound only plays on windows\n";
__END__
on Linux, which there of cause only shows the message?
Thanks
torben.
Re: how to write non-compatible perl scripts to run on differnet operating systems?
am 27.11.2007 13:17:33 von Peter Makholm
Torben writes:
> is it possible to make some kind of pragmas in perl scripts, so for
> example I can run a perl script like this:
You can use $^O or $Conifg{osname} with Config.pm.
//Makholm
Re: how to write non-compatible perl scripts to run on differnet operating systems?
am 27.11.2007 15:17:58 von Petr Vileta
Torben wrote:
> Hi to all,
>
> is it possible to make some kind of pragmas in perl scripts, so for
> example I can run a perl script like this:
> __BEGIN__
> #use Win32::Sound;
> Win32::Sound::Play("SystemExclamation");
> print "sound only plays on windows\n";
> __END__
>
> on Linux, which there of cause only shows the message?
>
if($^O eq "MSWin32")
{
use Win32::Sound; # not tested, maybe you can uncomment next line
#require Win32::Sound;
Win32::Sound::Play("SystemExclamation");
}
else
{
print "sound only plays on windows\n";
}
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to
Re: how to write non-compatible perl scripts to run on differnet operating systems?
am 27.11.2007 15:48:53 von jurgenex
Petr Vileta wrote:
> if($^O eq "MSWin32")
> {
> use Win32::Sound; # not tested, maybe you can uncomment next line
This does not do what you probably expect it to do. The 'use' is executed at
compile time already regardless of the evaluation of the 'if' which happens
much later at runtime.
You should use 'require' instead as mentioned in the docs for 'use'.
jue
Re: how to write non-compatible perl scripts to run on differnet operating systems?
am 27.11.2007 19:51:45 von Keith Keller
On 2007-11-27, Jürgen Exner wrote:
> Petr Vileta wrote:
>> if($^O eq "MSWin32")
>> {
>> use Win32::Sound; # not tested, maybe you can uncomment next line
>
> This does not do what you probably expect it to do. The 'use' is executed at
> compile time already regardless of the evaluation of the 'if' which happens
> much later at runtime.
>
> You should use 'require' instead as mentioned in the docs for 'use'.
There is also the "use if" pragma, available in recent versions of Perl;
something like (completely untested)
use if ($^O eq 'MSWin32') , 'Win32::Sound' ;
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information