PDA

View Full Version : What are the differences between Perl in Unix and Under Win2k?


RichardPac
11-06-2002, 11:57 PM
I have been using perl in a Unix environment running Apache server, but I have recently installed IIS 5.0 on a new webserver and have found a world of difference!

I have installed a perl intrepreter and even associated .cgi files with the perl program, but my scripts still won't run at all. I have tried running my scrips from a cmd line on the system and still, I have no luck with the output. Under the apache system i can simply type ./some.cgi to actually run the script and do limited error corrections.

How would I accomplish the same in the win2k environment?

Does anyone know of a good tutorial explaining the differences between the Unix and 2k platforms? How would my scripts have to change in order to run?

I have tried all day to find some information, but haven't stumbled upon a good starting point..

Any help would be appericiated.

Thanks in advance,
Richard Paczkowski

Mouldy_Goat
11-07-2002, 10:34 PM
I have installed a perl intrepreter and even associated .cgi files with the perl program, but my scripts still won't run at all. I have tried running my scrips from a cmd line on the system and still, I have no luck with the output. Under the apache system i can simply type ./some.cgi to actually run the script and do limited error corrections.

How would I accomplish the same in the win2k environment?

If you're using an interpreter like the ActivePerl one, it should automatically add the Perl interpreter's path to the PATH environment setting, so you should simply be able to type perl some.pl To run a script of yours.

More specifically, if you make a file like this:
#!/usr/bin/perl

print "Hello world!\n";
And save it as 'some.pl' in the directory 'C:\stuff\perl', then by opening command prompt and navigating to that directory and typing 'perl some.pl' at the prompt it should print out Hello world!

If you're just double clicking a file associated with the interpreter, the script will execute and then quit. That is, unless you have something in your script to make it not quit immediately, you will only see a brief flash of a command prompt window to show that it ever ran.

How would my scripts have to change in order to run?

If they're written in good Perl - they wouldn't have to change at all. This is one of Perl's greatest features. Even on systems which are completely different the script should act in the same way. A macintosh should be able to get the same functionality out of a Perl script as a PC.

If they've got slightly dubious bits of code, such as system calls (i.e. trying to run external programs from the script which are perhaps platform-dependent), then the code in question will need to be changed.

For instance something you might see is:
#!/usr/bin/perl

@output = `dir`;
foreach (@output) { print; }

Here, the 'dir' command is being invoked by the script on the OS. On a system without the 'dir' command - this script wouldn't work. There's almost always a better alternative to use which uses Perl alone, for instance if you wanted a listing of all the files in the directory you could just go:
#!/usr/bin/perl

while (<*>) { print "$_\n"; }

Does anyone know of a good tutorial explaining the differences between the Unix and 2k platforms?

Not off the top of my head, but I did a search which seems to have cropped up some fairly decent results just here (http://www.google.com/search?hl=en&lr=lang_en&ie=ISO-8859-1&as_qdr=all&q=perl+windows+tutorial+IIS&lr=lang_en).

Hope that helps a bit.

RichardPac
11-07-2002, 10:39 PM
Thank you so much.. At least now I have a place to start!

Richard Paczkowski