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

I'm interested in writing a script to perform a checkout from a CVS repository as well as tar'ing the resulting directory structure. Is is possible to: system "cd", $directory; system "cvs", "co", $module; system "tar", "-cvfX", $tar_file, $exclude_file, $module; . . . and have it execute as if it were from a single session? In other words, after doing the 'cd' and cvs command, the resulting directory $module is in $directory? Snippets of code would be helpful also. Tnanks is advance.

Replies are listed 'Best First'.
Re: perl shell utility scrips
by mitd (Curate) on Aug 30, 2001 at 11:27 UTC
    You may want to checkout VCS::CVS a module that provides a simple interface to CVS.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

Re: perl shell utility scrips
by clemburg (Curate) on Aug 30, 2001 at 13:28 UTC

    Is is possible to: system "cd", $directory; system "cvs", "co", $module; system "tar", "-cvfX", $tar_file, $exclude_file, $module; . . . and have it execute as if it were from a single session?

    No. Each system() command runs in its own process. That means that, e.g., system("cd $directory") has no effect on the following commands.

    Use the Perl equivalents of these (e.g., chdir(), Cwd, File::Copy, some CVS interface module (see replies above), and what else you need), and you get safety and portability for free.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Re: perl shell utility scrips
by virtualsue (Vicar) on Aug 30, 2001 at 13:32 UTC
    If that's all you need to do, it sounds like a shell script would be more appropriate. Perl has things in common with shell scripting, but it's a lot more than that. I wouldn't use it simply to automate a few simple tasks in a way that doesn't use any of the features of Perl. Writing shell scripts in Perl can only make the whole process slower than doing it in shell in the first place.
      While I do agree with virtualsue, I have a dissenting opinion. I am very new to perl, and programming itself. I can write shell scripts, but they tend to be limited. So I started writing my shell scripts in perl. It has taught me alot! The one most important thing I got out of it was this: I overcame my fear of perl, and it's structure, syntax, etc... I am making myself more comfortable with it each day I use it, and when I need the more advanced functions, I search on perlmonks and try to implement what I've seen. It's tough for me because the last time I wrote programs was about 14 years ago in high school, and that was in basic, and pascal on a TRS-80 (I loved my model 4). So while I agree that dfg2's script would best be written in #!/bin/ksh it might not be the best way to get into perl for a person just (re)starting programming.
      -spartan

      Very funny Scotty... Now PLEASE beam down my PANTS!
        I am all for writing Perl programs - I do it myself all the time. It's just that the sequence of tasks in question is a perfect example of something that can be done quickly & simply in shell, and not so easily in Perl. I'm not saying you're wrong, because you're not. It's easier to learn a language if you have a motivation, something that you need to accomplish. But in this case I think he'd be struggling with it days after starting, when he'd have a tool he could use that would make his life easier in a few minutes using the shell language of his choice.

      What about the Shell Module?