Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

How to move a windows perl installation??

by blueAdept (Beadle)
on Jul 21, 2004 at 15:15 UTC ( #376275=perlquestion: print w/replies, xml ) Need Help??

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

I'm made some attempts towards doing this, but I'm looking for others experience/insights. I'm not sure this is a windows specific question, but thats the platform I'm using. If on my windows machine I build/install(perl 5.8.4) perl to lets say D:\utils\perl, and I later want to move it to another location -- what do I need to do?

Simply copying it isn't enough since modules I've installed contain the original path. Do I need to copy, and then parse every text file to substitute out the old path with the new one? Is that enough/everything? What about binary files like .dll's -- are those not of concern? Appreciate any insights or references. thanks!
  • Comment on How to move a windows perl installation??

Replies are listed 'Best First'.
Re: How to move a windows perl installation??
by gellyfish (Monsignor) on Jul 21, 2004 at 15:22 UTC

    If you are using the Activestate Perl then you will have a reloc_perl.bat in the bin directory which it uses to perform the initial relocation when it is installing.


      Thanks but i'm not using ActiveState's perl. I'm building the normal perl distribution myself. I figured they are doing "something" like this, but I don't want to ripp off of them -- so i'm not even going to look inside of that script/file :-) And I was curious if this was a platform specific or generic issue.. (would seem to be a generic one right?)
        Tha main point is the change of the value FROMPATH (let's say c:\perl) to DESTPATH (c:\utils\perl) from all the executable files. On Win32 are all the scripts, bat and perl.exe. On linux are the scripts and perl binary.

        So, the change for scripts and bats are just to change one scring to another. For binaries is just to change the value but keeping the size:

        my $nullpad = "\0" x (length($frompath) - length($destpath)) ; open (FROM,"c:\perl\bin\perl.exe") ; binmode(FROM) ; open (TO,">c:\utils\bin\perl.exe") ; binmode(TO) ; while( my $line = <FROM> ) { $line =~ s/\Q$frompath\E(.*?)\0/$destpath$1$nullpad\0/gs ; print TO $line ; } close (TO) ; close (FROM) ;
        So, for scripts is 100% portable, and for binaries it should be 100% portable too, but the DESTPATH need to fit in the reserved area for the string (char*) in the constant in the binary. In other word, the DESTPATH need to be small to guarantee that it will worl 100%.

        Graciliano M. P.
        "Creativity is the expression of the liberty".

Re: How to move a windows perl installation??
by CountZero (Bishop) on Jul 21, 2004 at 15:29 UTC
    I would first take a snapshot-bundle with the CPAN-module of my Perl-modules and then re-install basic Perl at the other location. Then I would use the CPAN module again to recreate my previous Perl-tree.

    On the other hand, except for the basic Perl-install, I don't think the dll's in the "Perl/lib/site"-modules mind being moved around as they are dynamically called by Perl itself and do not seem to mind being moved around.

    Of course some configuration files ( springs to mind) may need to have their paths adjusted.

    Of course you could always write a Perl script to adjust the paths! (this is left as an excercise for the interested reader)


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: How to move a windows perl installation??
by tachyon (Chancellor) on Jul 21, 2004 at 23:33 UTC
    #!/usr/bin/perl use strict; use ActiveState::RelocateTree qw(relocate spongedir rel2abs); use Config; use Getopt::Std; use vars qw( $opt_a $opt_b $opt_d $opt_e $opt_f $opt_i $opt_t $opt_r $opt_v *OLDERR ); my $logname; BEGIN { # If we're being run via wperl, redirect the output streams to a l +og file. if ($^O eq 'MSWin32' and $^X =~ /\bwperl(.exe)?\z/i) { my $tmp = $ENV{TEMP} || $ENV{tmp} || "$ENV{SystemDrive}/" || "c:/t +emp"; $logname = "$tmp/ActivePerlInstall.log"; open(STDERR, ">> $logname"); open(STDOUT, ">&STDERR"); } } my $frompath_default = $Config{prefix}; getopts('abde:f:itrv') or usage(''); my $topath = shift || usage(''); my $frompath = shift || $frompath_default; # MSI insists on handing us paths with backslashes at the end if ($^O eq 'MSWin32') { $topath =~ s{\\\z}{}; $frompath =~ s{\\\z}{}; } my $destpath = $opt_e || $topath; my $filelist = $opt_f || ''; usage("$destpath is longer than $frompath") if length($destpath) > length($frompath) and ! $opt_a; usage("$destpath is longer than " . spongedir('thisperl')) if length($destpath) > length(spongedir('thisperl')) and ! $opt_t; if (-d $topath) { if (not -d $frompath) { #warn "Will do inplace edit of `$topath'\n"; $opt_i++; } } elsif ($opt_i) { usage("Directory `$topath' doesn't exist, can't do inplace edit"); } sub usage { my $msg = shift; warn <<EOT; $msg Usage: $0 [-a] [-b] [-d] [-e destpath] [-f logfile] [-i] [-t] [-r] [- +v] topath [frompath] -a allow destpath to be longer than frompath -b don't delete backups after edit -d delete source tree after relocation -e destpath edit files to contain this path instead of `fr +ompath' (defaults to `topath') -f logfile creates `logfile' and writes the full path nam +e of each file that was modified (one line per fi +le) -i edit perl installation at `topath' insitu (makes no attempt to move tree, -d is ignore +d) -t only edit text files -r do not run `ranlib' on *.a files that were edi +ted -v verbose messages 'destpath' defaults to `topath' 'frompath' defaults to '$frompath_default' 'destpath' must be shorter than 'frompath' unless the -a option is specified. 'destpath' must shorter than the path built into this Perl binary, unless the -t option is given. The -a switch cannot override this restriction. -i is assumed if `topath' exists, is a directory, and `frompath' doesn't exist. EOT exit(1); } relocate( to => $topath, from => $frompath, replace => $destpath, verbose => $opt_v, filelist => $filelist, ranlib => (not $opt_r), textonly => $opt_t, savebaks => $opt_b, inplace => $opt_i, killorig => $opt_d, usenlink => 0, # don't use nlink: broken on HP-UX. ); __END__ =head1 NAME reloc_perl - relocate a perl installation =head1 SYNOPSIS reloc_perl [-a] [-b] [-d] [-e destpath] [-f file] [-i] [-t] [-r] [-v +] topath [frompath] =head1 DESCRIPTION This tool will move a perl installation wholesale to a new location. Edits path names in binaries (e.g., a2p, perl, libperl.a) to reflect t +he new location, but preserves the size of strings by null padding them a +s necessary. Edits text files by simple substitution. 'destpath' cannot be longer than 'frompath'. If 'frompath' is not found in any files, no changes whatsoever are mad +e. Running the tool without arguments provides more help. =head1 COPYRIGHT (c) 1999-2001 ActiveState Tool Corp. All rights reserved. =cut



      =head1 COPYRIGHT (c) 1999-2001 ActiveState Tool Corp. All rights reserved.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://376275]
Approved by Paladin
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-01-19 08:55 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (55 votes). Check out past polls.