zilore mumba wrote:
> Perl Users,
> Firstly my apologies for my very elementary knowledge of Perl.
> Thanks to ideas from Sena and Mustafa, and a lot of assistance from Bill
> Luebkert on an earlier script, I have below a snippet from a script
> which I tohught should work.
> The problem is $base_dir, which is supposed to be
> /home/Mumba/archive/11-November08/ukmo/20081115 is being put on several
> lines as
> /home/Mumba/archive/11
> -
> November08
> Hence my chdir ("$base_dir/$dat") gives the error "cannot cd", no such
> file or directory. I have another script which works, with a similar but
> even longer directory. I do not see the difference.
> Is there some trick I can do to force the whole directory on one line?
1) Your use of model sometimes in the base_dir and sometimes not is confusing.
2) I don't like shelling out or globbing, so I didn't use them.
3) I put the combined file up a dir in base_dir so you don't have to worry
about it in the unlink step
4) I ran on Windoze - hence the 'E:/tmp' on your base dir
# this runs on Win32 (without actually doing the 2 system calls):
use strict;
use warnings;
# define stuff you're using that's not defined
my $debug = 0;
my $model_mon = '11';
my $dash = '-';
my $mon_name = 'November';
my $yr = '2008';
my $model = 'ukmo';
my $cycle = 'cycle';
my $grib_ext = 'grib';
my $ctl_ext = 'ctl';
my $dat = '20081115';
my $base_dir = "E:/tmp/Mumba/archive/$model_mon$dash$mon_name$yr/$model";
my $ofile = "$base_dir/$model$cycle.$grib_ext";
# (Note it's confusing whether model is part of base_dir or not)
# cd to base/date dir
chdir "$base_dir/$dat" or die "chdir '$base_dir/$dat': $! ($^E)";
# open output file - put it up a dir in base_dir so it doesn't get deleted
print "Creating output file '$ofile'\n" if $debug;
open OUT, ">$ofile" or die "Create '$ofile: $! ($^E)";
binmode OUT;
# do foreach file in dir
opendir DIR, "$base_dir/$dat" or die "opendir '$base_dir/$dat': $! ($^E)";
while (my $file = readdir DIR) {
next if $file =~ /^\.\.?/;
print "Adding '$file'\n" if $debug;
open IN, $file or die "open '$file': $! ($^E)";
binmode IN;
while (<IN>) { print OUT $_; }
close IN;
}
closedir DIR;
close OUT;
# run script on output file and some other ctl file (I have no idea what this
# does)
my $cmd = "/usr/bin/perl /usr/local/bin/grib2ctl.pl -verf " .
"$base_dir/$model$cycle.$grib_ext > $model$cycle.$ctl_ext";
print "doing system ($cmd)\n" if $debug;
system ($cmd);
$cmd = "/usr/local/grads/bin/gribmap -i $base_dir/$model$cycle.$ctl_ext -v -e";
print "doing system ($cmd)\n" if $debug;
system ($cmd);
opendir DIR, "$base_dir/$dat" or die "opendir '$base_dir/$dat': $! ($^E)";
while (my $file = readdir DIR) {
next if $file =~ /^\.\.?/;
print "unlinking '$file'\n" if $debug;
unlink $file or warn "unlink '$file' failed: $! ($^E)";
}
closedir DIR;
__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs