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

my $home_dir= ($ENV{HOME}); my $date = $ARGV[0]; my $program = "/nfs/cooler/users/limo/bin/gen-cflowd-config"; my $matrix = "netmatrix"; my $config_path = "/nfs/cooler/users/limo/config/$date"; my $out_dir = "$home_dir/flowstats/configs/$date"; #If your "router-to-collect-flow" is not here, edit path below. my $config_file = "$home_dir/flowstats/router-to-collect-flow.$ARGV[0] +"; my %hash; my $host; my $line; my $key; my $string; my ($router, $cache, $nta, $as, $SampleRate); die "Usage: $0 <yyyymmdd> This program assumes:\n 1. the directory structure \$HOME/flowstats/configs.\n 2. you are running this on chipotle.\n If either of the above differs, you will need to make the appropriate modifications to this program.\n" unless @ARGV == 1; if (! -d "$out_dir") { system "mkdir $out_dir"; } chdir "$home_dir/flowstats/configs/$date" || die "Cannot change direct +ory:$!\n"; print "Writing configs to $out_dir\n";
The problem is that the new directory is not being created. What's wrong?

Replies are listed 'Best First'.
(jeffa) Re: External command problem
by jeffa (Bishop) on Mar 07, 2001 at 21:38 UTC
    Try using the -p option for mkdir. This will create the whole directory tree for you.

    Another issue: you should check for the presence of ARGV's before you actually do anything with them:

    die &USAGE unless @ARGV == 1; # yes, put it in a sub # ... my $date = $ARGV[0]; my $out_dir = "$home_dir/flowstats/configs/$date";
    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
      You could think about using File::Path rather than mkdir -p which is less than fully portable.
      -- I knock my pate and fancy wit will come Knock as I please, there's no one at home a pontiff paraphrased
Re: External command problem
by AgentM (Curate) on Mar 07, 2001 at 22:15 UTC
    ...just like the chdir you use, mkdir is perl built-in function. Avoid the overhead and use that instead. You ask "what's going wrong" but you don't even bother checking for errors at the system call. If it interests you what is going wrong, check return values at your critical points.
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
Re: External command problem
by Limo (Scribe) on Mar 07, 2001 at 23:17 UTC
    Update: No need to respond to this. Although both jeffa and AgentM had good criticisms (which I did incorporate :) ), my real problem was a mis-named variable.