hawthorne has asked for the wisdom of the Perl Monks concerning the following question:

Hi all. My hosting company recently moved my website to a different server, which broke the perl script that drives the site. Unfortunately, I wrote the script a good three years ago as part of an arts-based masters degree project (and with crucial help from people on this forum—thanks again!) and I have no idea how to follow the brief advice offered by my hosting company to fix the problem. I was never a programmer to begin with, and despite spending all day trying to Google my way to self-sufficiency on this I just can't get my head around it.

Here's what the hosting company said:

Your perlmods directory uses libs from perl 5.8.4 (which was the older version of perl on your old server), but your new server has perl version 5.8.8. You need to replace those old lib files with new ones for perl version 5.8.8.

Here are my questions:

Where can I download the new lib files? Which files do I need? And can I simply create 5.8.8 folders in my perlmods/lib/perl and perlmods/share/perl directories via FTP and put the files in there?

Here is my script, if that's relevant:

#!/usr/bin/perl -wT use strict; use CGI ':standard'; print "Content-type:text/html\n\n"; use lib '/home/jesskilb/perlmods/share/perl/5.8.4'; use lib '/home/jesskilb/perlmods/lib/perl/5.8.4'; use File::Random qw/:all/; my $dir = '/home/jesskilb/the-spam-oracle.com'; my $file = random_file(-dir => "$dir/infinity"); my @lines = random_line("$dir/infinity/$file", int(rand(3)) + 1); my $randomlines=join(" ",@lines); open(OUTPUT,"$dir/results_template.html") or die "Can't open file\n"; my $line; while ($line=<OUTPUT>) { $line=~s/results go here/$randomlines/; print $line; } close OUTPUT;

Any help would be MUCH appreciated, particularly if you could write it as if for a very simple-minded 5-year-old. Thanks in advance!

Replies are listed 'Best First'.
Re: How do I update my perlmod lib files to 5.8.8?
by jevaly (Sexton) on Oct 20, 2009 at 07:21 UTC
    New modules can be downloaded at CPAN: File::Random, allthough I'm not really sure you need a new module, most modules that ran under 5.8.4 will run fine on 5.8.8.
    Wether or not you can create new directories on your server will depend on the administrator of that server; here your webhost I think. Just try it and you'll see.
    However, generally it's a bad idea to include hardcoded directories in your script using the 'use lib' pragma. (any move of server/version would mean you need to change the script) The preferred way would be to let the webhoster include these packages in their perl distribution. Don't know if that's possible though.

      I'm beginning to think this is the best way forward. What would I need to add to my script to replace the 'use lib' lines and instead use my webhost's packages? I'm sure they would be willing to add them, if they don't already have them.

      Also, do I need to undo the symbolic link between 5.8.4 and 5.8.8 that I made while I was experimenting, and if so how do I do that?

      Thank you!

Re: How do I update my perlmod lib files to 5.8.8?
by jethro (Monsignor) on Oct 20, 2009 at 08:41 UTC

    As a quick fix you could, as jevaly suggests, do this on the server:

    cd /home/jesskilb/perlmods/share/perl ln -s 5.8.4 5.8.8

    This would create a symbolic link that would trick perl into using the old library. Alternatively, if you don't have shell access on the server, just upload a dir 5.8.8 in perlmods/share/perl with the same contents you find in the 5.8.4 directory

    If not, just download the File::Find source here and store that file into perlmods/share/perl/5.8.8/File/Find.pm

      Symlinking does not look like a good idea to me. hawthorne wrote that his installation was moved to a different server, propably with a newer OS version, different library versions, different (g)cc version, and so on. Even perl itself may have been compiled differently. So, while the pure Perl part of the modules should survive that quite easily, the XS libraries may not be binary compatible and will probably cause segfaults and other unexpected behaviour.

      The best bet here is to install all required modules from CPAN, using Perl's cpan utility.

      With access to the old server, creating an autobundle on the old server and installing it on the new server should be the easiest way.

      Without access to the old server, you need to find the required modules manually. I would start by grepping all existing code for lines containing "use" or "require", followed by extracting the loaded modules, and finally creating a distinct, ordered list of modules. find, grep, sort, and uniq could help, or a little Perl script with File::Find, grep, sort, and a hash of module names. With that list, I start the cpan utility and make it install each and every module on the list, either manually using the cpan utility or by using the CPAN API.

      After that, every single application has to be tested, and watched for errors. (Hint: Read the web server's error log.) All modules that are still missing have to be installed, as above.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Hmmm. I tried each of these suggestions and none of them seem to be working.

      First I downloaded the 5.8.4 directories in share/perl and in lib/perl, renamed them to 5.8.8, and re-uploaded them. For this approach I also changed the "use lib" lines of my script to 5.8.8. Should I have done that?

      Next I tried creating the symbolic link (I do have shell access), but that didn't work either. I changed my "use lib" lines back to 5.8.4 for this.

      Last I downloaded the File::Find (it was actually File::Random, and I'm guessing you meant to write that, too?) and uploaded it (as Random.pm) into the 5.8.8 dir I'd already created in my first approach, which overwrote the version of the file that was already there.

      In all instances I continued to get the 500 Internal Server Error message. Have I misinterpreted any of your suggestions, or left out a required step due to ignorance? If not, any ideas why these solutions aren't working, and/or suggestions for other approaches to try?

      (Also: thank you!)

        I had assumed File::Random was the only file needed. But you can check that, just search /home/jesskilb/perlmods/share/perl/5.8.4 for other files beside File/Random.pm. When I look at the source, the only missing module I can see is Want, everything else should probbly be included in 5.8.8. If there are a lot or more "complicated" ones (for example with *.so files), it is best to install them the normal way, like afoken said.

        Since you have a shell you might try the following: Just execute your script on the command line and observe the error messages. First without any libraries, then successively add the ones the script complains about missing. This should give you lots of hints what libraries are missing or whether the problem is elsewhere