how to write non-compatible perl scripts to run on differnetoperating systems?

T

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.
 
P

Peter Makholm

Torben said:
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
 
J

Jürgen Exner

Petr said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top