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

Hi Monks,

I come seeking some guidance on the best way for me to perform multiple file copies and log the time at which the file copy was performed. I've created the following script that runs great on ActiveState perl on my Windows laptop, however when I move it over to a linux box it no workie....

Here is the script that I have written:
#!perl -w ###################################################################### +######### # File copier logger ###################################################################### +######## use strict; use Time::localtime; use File::Copy; $copyLog = "perlCopy.log"; $now = ctime(); open(COPYLOG, ">> $copyLog") or die "can't open the log file"; $count=1; while ($count < 28) { $count+=1; $fileCopy = "lab-as-h06-vm$count.dsk"; if($count < 10) { $fileCopy = "lab-as-h06-vm0$count.dsk"; } copy("lab-as-h06-vm01.dsk","$fileCopy"); print COPYLOG "$fileCopy copy started at $now \n"; }

When I run the script on my Linux box I get the following error:

Execution of fileCopy.pl aborted due to compilation errors.

I'm guessing it has to do with the File::Copy not being available. I'm not quite sure of the configuration of the Perl install on the Linux box as it is not my machine, but can anyone tell me where I should go from here. What Should I look at on the Linux box to ensure that the modules are available, Is there something my scripts should do differently on Linux?? All prayers welcome...

Replies are listed 'Best First'.
Re: File Copy on Linux
by Benedictus (Beadle) on Dec 16, 2003 at 18:32 UTC

    Could you be more explicit about the errors you are getting? Or do you only get "execution of fileCopy.pl aborted due to compilation errors"? I suspect that what you are really getting is a list of errors that looks like:

    Global symbol "$copyLog" requires explicit package name at fileCopy.pl line w.
    Global symbol "$now" requires explicit package name at fileCopy.pl line x.
    Global symbol "$copyLog" requires explicit package name at fileCopy.pl line y.
    Global symbol "$count" requires explicit package name at fileCopy.pl line z.
    

    Since you are using strict (which is a good idea), you need to declare your variables with 'my' or 'our'.

    Benedictus

      Thanks Benedictus,

      I forgot that I was using strict, it is now working on Linux....

      I'm heading over to the meditation area to remember the fundamentals...
Re: File Copy on Linux
by r11132a (Scribe) on Dec 16, 2003 at 18:44 UTC
    Hello!

    Your error might not necessarily be due to File::Copy not being installed.
    Since you (wisely) used strict you'll need to declare your variables with my ie:
    my $copyLog = "perlCopy.log";
    Now, to check for what modules are availible on a particular installation, there are two ways to go about it: the correct way and the quick way.

    The correct way is to use ExtUtils::Installed and check the list returned. ie:
    perl -MExtUtils::Installed -e'foreach(ExtUtils::Installed->new()->modu +les()){print"$_\n";}' | less
    This has the added advantage of informing you of all modules installed in the default location for this installation.

    The quick way is simple, but really just useful for checking if one specific module is installed:
    perl -MSome::Module -e'print"hello,world\n";'
    If the module isn't installed you'll get a "Can't locate Some/Module.pm" error.

    Hope this helps.
Re: File Copy on Linux
by mikedshelton (Beadle) on Dec 16, 2003 at 20:47 UTC
    I would suggest using "perl -c fileCopy.pl" to compile your program before trying executable
Re: File Copy on Linux
by Tuppence (Pilgrim) on Dec 17, 2003 at 00:38 UTC
    Whenever I want to be sure that a module exists on the specific system I'm on, I always start a quick little debugger session:
    $ perl -d -e 42 <DB1> use File::Copy <DB2> q $
Re: File Copy on Linux
by xenchu (Friar) on Dec 17, 2003 at 04:09 UTC

    Here is a program that runs on RH Linux 9 that will list all the Perl modules installed on the system:

    #!/usr/bin/perl - w # checkmodule.pl use strict; use File::Find; my @files; find sub { push @files, $File::Find::name if -f _ && /\.pm$ +/ }, @INC; my ($mod, $hash, $name); my (@results, %hash, @results2); @results = map {/.+\/.+\/(.*)\.pm$/} @files; #@results = sort {uc($a) cmp uc($b)} @results; #@results = map {/.+\/.+\/(.*)\.pm$/ and ucfirst($1)} @files; $hash{$_}++ foreach (@results); foreach (sort {uc($a) cmp uc($b)} keys %hash) { print "$_.pm \n"; } #@results2 = grep( ($hash{$_} == 1), keys %hash ); #print join "\n", @results2; #print "\n";

    BTW, I got the program here on Perl Monks. Someone listed it as part of their answer to a question asked. I wish I could remember where I got it so I could give proper attribution.

    xenchu


    The Needs of the World and my Talents run parallel to infinity.