Won't the Perl code run in Unix (our code will be running in Linux machines) and Windows both??
Perl and many modules will run just fine in both environments, and there is lots of Perl code that is entirely portable to many platforms. But in some cases, care has to be taken to ensure portability. For example, you'll often see code that is hard-coded to use the forward slash as a directory separator, which works in many cases on Windows, but not all. If instead one uses the core module File::Spec or one of the more user-friendly modules from CPAN like Path::Class, they'll do filename handling in a more native way, and you should have much less portability issues. When picking modules, you can look at their documentation as well as the CPAN Testers Matrix for compatibility (e.g. this is the one for IPC-Run3).
| [reply] |
You should be aware that if you specify a path with forward slashes to a Windows instance of perl, the interpreter will usually auto-convert the forward slashes to backslashes for file access. This is a particularly helpful feature when wrapping a Windows path in interpolating delimiters, e.g. double quotes. Obviously, File::Spec et al. represent the most transferable approach.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
| [reply] |
Actually, it's Windows itself that copes with forward slashes as well as backslashes, not Perl.
It is mostly the shell and UNC filenames that really need backslashes.
| [reply] |
Won't the Perl code run in Unix (our code will be running in Linux machines) and Windows both??
Definitely on Linux, and surely on Windows, too. But I don't have enough expertise on Windows to assert that all perl code portably written on Linux/UNIX runs on Windows without (trivial) changes. Others should step in here.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
| [reply] |
As with any 'portable' language, not all programs can be just copied between *nix and Windows. Many can, some can with effort, and others can't.
It is particularly difficult if the program has implemented functionality that relies on platform specific libraries for instance, or attempts to do things on an OS where the capabilities don't exist or work reliably ($SIG{ALRM} comes to mind).
Again though, the vast majority of the time, if a Perl script can't be migrated from one platform to another, neither can a similarly-written program written in another language.
Here's an example Makefile.PL of a Perl distribution that is specifically designed to work cross-platform. That file, and the entire codebase of the dist checks to see what OS its on, and sets itself up accordingly. In this case, the code had to be written in this fashion as it requires a lot of OS-specifics. Most of my other distributions are cross platform without any need to do any specific checking at all.
| [reply] [d/l] |