Perl compatibility - perl

This isn't my area of expertise so I'm asking hopefully the right question.
We have a server that is lease rolling. The old server is a 32-bit windows server and the new server is 64-bit windows 2008 R2 SP1.
One of the web applications uses Perl to run some scripts.
We can run the same 32bit version on the new 64-bit machine? (e.g. if there is a same version but one is 32-bit and one is 64-bit, are they essentially the same?)
If a script is working on a 32-bit version, should it still work under the 64-bit version of Perl?
If the questions need clarifying, please let me know and I'll see about asking the appropriate person on our team.

I think the answers to both your questions are yes. The 32-bit applications should run fine on your 64-bit Windows, but will not be able to utilize any of the 64-bit features (where a larger usable address space may very well be the most important if you ever want to parse big XML using XML::Twig ;-).
The script running under 32-bit perl will work on a 64-bit perl, provided you get all the modules for the 64-bit perl in order, since they typically run from different directories. Also, be aware that for 64-bit perl on Windows you probably need Strawberry perl, ActiveState perl or similar. Cygwin is only 32-bit as far as I know.

Yes, you can, as long as you redeploy properly, including the build steps for dependencies. Just copying files over will only work if the whole application stack is pure-Perl, which is not likely. — Yes, they are essentially the same, but binary incompatible.
Likely yes. Problems can arise with the dependencies, however the number of modules that fail due to 32-bit/64-bit differences are miniscule.

If you're concerned about compatibility, you should be able to run the 32-bit version of perl on the 64-bit machine (assuming both are x86). But the 64-bit version should work more or less the same as the 32-bit one, with a couple of exceptions that should not affect scripts. (They have to do with C/XS code in modules, mostly. Binary-compatibility stuff. Meaning modules will have to be built for 64-bit. Fortunately, any Perl interpreter that doesn't suck will do the build stuff for you in the case of *nix, or provide a package manager that has pre-built modules like ActiveState does.)

Related

apache2: Perl lib version (5.28.1) doesn't match executable '/usr/sbin/apache2' version (5.20.2)

I have installed Debian 10 in order to migrate a web server from one machine to this Debian 10 machine. The web server built on apache2 needs mod_perl. The module was not found on the new machine, so I installed perl5.28 (and mod_perl.so has been added). But now it seems there is a mismatch between a previous perl version (5.20) and the latest one (5.28). I use the perl binary correspondint to v5.28, #INC contains directories related to v5.28 (according to "env -i perl -V"). But when I try to start the apache2 server, I get this error: "apache2: Perl lib version (5.28.1) doesn't match executable '/usr/sbin/apache2' version (5.20.2)". Can anyone help? Thanks a ton in advance.
When you built apache with mod_perl, you used v5.20, but it seems that's not around anymore. Different versions of Perl are not guaranteed (or even attempt to be) binary compatible. Between Perl versions, you'll likely have to re-compile all XS modules, too.
You need to recompile apache with the Perl that you want to use, or install the Perl that apache wants to use. This time you may want to statically compile mod_perl into apache.
This problem isn't specific to Perl, though. Many software libraries will complain similarly when you replace the library they compiled against.

How to make perl script thinks that it's running on 64-bit machine?

How can I make a Perl script think that it is running on 64-bit machine? It needs to perform binary parsing of data that was written on a 64-bit machine, but it needs to be parsed on a 32-bit machine (via argument flag, for example). In my code I using pack/unpack with the formatting 'L!4'.
If your problem is to be sure that the script works correctly on a 64bit machine, I suggest you use VirtualBox to install a 64bit version of the OS.
See: https://superuser.com/questions/25495/virtual-machine-running-64bit-from-a-32bit-system
But if you need that only to "exploit" the "L!4" mask maybe you should look for a different solution? (e.g.: have you tried to see if your PERL version supports "Q" instead of "L"?)

How should I distribute a pre-built perl module, and what version of perl do I build for?

This is probably a multi-part question. Background: we have a native (c++) library that is part of our application and we have managed to use SWIG to generate a perl wrapper for this library. We'd now like to distribute this perl module as part of our application.
My first question - how should I distribute this module? Is there a standard way to package pre-built perl modules? I know there is ppm for the ActiveState distro, but I also need to distribute this for linux systems. I'm not even sure what files are required to distribute, but I'm guessing it's the pm and so files, at a minimum.
My next question - it looks like I might need to build my module project for each version of perl that I want to support. How do I know which perl versions I should build for? Are there any standard guidelines... or better yet, a way to build a package that will work with multiple versions of perl?
Sorry if my questions make no sense - I'm fairly new to the compiled module aspects of perl.
CLARIFICATION: the underlying compiled source is proprietary (closed source), so I can't just ship source code and the appropriate make artifacts for the package. Wish I could, but it's not going to happen in this case. Thus, I need a sane scheme for packaging prebuilt binary files for my module.
I look after DBD::Informix, one of the Perl Database Driver modules that works with the DBI (Perl Database Interface). The underlying libraries used to connect to IBM Informix Dynamic Server (IDS) are proprietary, but the DBD::Informix code itself is not. I distribute that code on CPAN, just the same as any other Perl module. People can download that source, and (provided that they have the Informix ClientSDK installed on their machine - and Perl and DBI and so on), they can build DBD::Informix to work with their installed Perl.
I would strongly counsel that you arrange that your Perl interface code be made available in source form, even though the library that it interfaces to is proprietary. This allows people to install the code with any version of Perl they have - without requiring you to deal with inconsistencies.
If you still want to provide binary support, you are going to have to work out which platforms you want to support, and build the module with the standard version of Perl on each such platform. This gets messy. You need access to an instance of each machine. Granted, virtual machines make this easier, but it is still fiddly and the number of platforms and versions only grows. But you still need to support people who don't use the standard version of Perl on their machine - that's why the Perl wrapper interface needs to be provided in source form.
DISCLAIMER: I have next to no experience creating binary packages that can easily be installed. Therefore, I am making this post CW to make it easier for others to add their advice.
You should make the distribution available in source form so it can be compiled on each system tailored according to the specifics of that system. I really like Module::Build for that purpose.
For ActiveState users on Windows, you probably want to have four or six PPMs based on whether you want to support 5.6. Package both 32-bit and 64-bit versions for each of 5.6, 5.8 and 5.10. Use the version of mingw you can install using ppm to compile the modules to preserve binary compatibility.
Another option is to use PAR::Packer and distribute your application in a PAR archive. In that context, PAR::WebStart might be useful although I have not tried it. I have had success with PAR archives in the past, though.

How can I compile 64-bit Postgres bindings for Perl on Solaris?

I'm running 64-bit Solaris 10, and I have self-compiled Perl 5.10 and Postgresql 8.4.1 installed in /usr/local, both 64 bits. Solaris came with 32-bit Postgresql 8.1.4 installed in /usr, but it is not running. When I attempt to install DBD::Pg, it hits a problem because the libpq.so it finds is the 32-bit one in /usr/lib rather than the 64-bit one in /usr/local/pgsql/lib.
# /usr/local/bin/cpanp -i DBD::Pg
Installing DBD::Pg (2.15.1)
...
ld: fatal: file /usr/lib/libpq.so: wrong ELF class: ELFCLASS32
My first thought was to remove the bundled Postgres, but I've read advice against that. I'm sure everything would work if I started over with 32-bit Perl, but I'd prefer to stick with what I have.
I noticed in the CPAN output that the makefile sets LD_RUN_PATH=/usr/lib prior to linking. That seems like something that should change, but I don't know how to change it (since it's all automated by CPAN), and I don't know what other side effects such a change might have. It looks like the correct directory, /usr/local/pgsql/lib, isn't on the path at all, so maybe just making that visible would resolve the problem even without hiding the 32-bit version, but I don't know how to do that, either.
How can I get this module compiled in the environment I have, or how can I change my environment so the module will compile as-is?
From http://cpansearch.perl.org/src/TURNSTEP/DBD-Pg-2.15.1/Makefile.PL
In brief:
By default Makefile.PL uses App::Info to find the location of the
PostgreSQL library and include directories. However, if you want to
control it yourself, define the environment variables POSTGRES_INCLUDE
and POSTGRES_LIB, or define just POSTGRES_HOME. Note that if you have
compiled PostgreSQL with SSL support, you must define the POSTGRES_LIB
environment variable and add "-lssl" to it, like this:
export POSTGRES_LIB="/usr/local/pgsql/lib -lssl"

How can I package my Perl script to run on a machine without Perl?

People also often ask "How can I compile Perl?" while what they really want is to create an executable that can run on machines even if they don't have Perl installed.
There are several solutions, I know of:
perl2exe of IndigoStar
It is commercial. I never tried. Its web site says it can cross compile Win32, Linux, and Solaris.
Perl Dev Kit from ActiveState.
It is commercial. I used it several years ago on Windows and it worked well for my needs. According to its web site it works on Windows, Mac OS X, Linux, Solaris, AIX and HP-UX.
PAR or rather PAR::Packer that is free and open source. Based on the test reports it works on the Windows, Mac OS X, Linux, NetBSD and Solaris but theoretically it should work on other UNIX systems as well.
Recently I have started to use PAR for packaging on Linux and will use it on Windows as well.
Other recommended solutions?
In addition to the three tools listed in the question, there's another one called Cava Packager written by Mark Dootson, who has also contributed to PAR in the past. It only runs under Windows, has a nice Wx GUI and works differently from the typical three contenders in that it assembles all Perl dependencies in a source / lib directory instead of creating a single archive containing everything. There's a free version, but it's not Open Source. I haven't used this except for testing.
As for PAR, it's really a toolkit. It comes with a packaging tool which does the dependency scanning and assembly of stand-alone executables, but it can also be used to generate and use so-called .par files, in analogy to Java's JARs. It also comes with client and server for automatically loading missing packages over the network, etc. The slides of my PAR talk at YAPC::EU 2008 go into more details on this.
There's also an active mailing list: par at perl dot org.
It is some time since this question was first asked, but Cava Packager can currently produce executable packages for Windows, Linux and Mac OS X. It is no longer Windows only.
Note: As indicated by my name, I am affiliated with Cava Packager.
I'm a Perl newbie and I just downloaded Cava Packager and that's the only one I found working. I've tried ActiveState 5.10.1005 and Strawberry Perl with PAR-Packager on Windows XP.
pp just hangs in mid-stream and no executables created.
Cava provides the only solution to creating exe on Windows so far. Thks.
You could use the perlcc tool that's shipped with most distributions of Perl. I've also found both perl2exe and Active State's Perl Dev kit useful for shipping Perl applications.