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

Hi all. :)
I'm writing a small bit of code that has a use statement in it that looks in a library called "ccr".

The statement is 'use perl::net::utils'
It looks for Utils.pm.

What I want to do in the script is before the use statement, have perl check to see if (pwd)\perl\net\Utils.pm actually exists, and if it doesn't, check it out from a cvs library called ccr.

Sounds pretty simple to me, but I'm really, really new at this and don't really know where to begin.

Any insight appreciated. =) Thanks!
  • Comment on Need a quick file check/checkout script if anyone has a moment. :)

Replies are listed 'Best First'.
Re: Need a quick file check/checkout script if anyone has a moment. :)
by idsfa (Vicar) on Sep 30, 2004 at 17:33 UTC
    sub install { use Cvs; my $cvs = new Cvs ( '/path/to/repository/for/module', cvsroot => ':pserver:user@host:/path/to/cvs', password => 'secret' ) or die $Cvs::ERROR; $cvs->checkout('module'); use perl::net::utils; } eval "use perl::net::utils" or &install;

    The CPAN docs for CVS can provide more info ...


    If anyone needs me I'll be in the Angry Dome.

      The use in the sub also needs to be wrapped in an eval or Perl will find it at compile time and barf if the module is not installed. You could use a require + call import.

      cheers

      tachyon

Re: Need a quick file check/checkout script if anyone has a moment. :)
by si_lence (Deacon) on Sep 30, 2004 at 15:40 UTC
    hello
    The first part (checking for the existance) is easy:
    if (-e $path) { print "$path exists\n"; }

    as for the checkout ... I hope someone else can help.
    si_lence
      Hm, here's what I have: ---
      use perl::net::Utils;

      if (-e $path) {
      print "$path exists\n";
      }

      my $time = Dtg( time() );
      print "The DTG time is $time\n";


      (dtg is a module from utils.pm)

      I get a 'use of uninitialized value in -e' error.

      Thanks very much for the quick response, really appreciate it. =)
        you need to set the $path variable to the path of the file you want to test. So in your case:
        use strict; use warnings; use perl::net::Utils; my $path ='\perl\net\Utils.pm'; if (-e $path) { print "$path exists\n"; } #more code here
        si_lence