Long directory structure on one line

Long directory structure on one line

am 15.11.2008 12:22:02 von zilore mumba

--===============1646407192==
Content-Type: multipart/alternative; boundary="0-1412090527-1226748122=:24762"

--0-1412090527-1226748122=:24762
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

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 Lu=
ebkert on an earlier script, I have below a snippet from a script which I t=
ohught should work.
The problem is $base_dir, which is supposed to be
/home/Mumba/archive/11-November08/ukmo/20081115 is being put on several lin=
es 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 l=
onger directory. I do not see the difference.
Is there some trick I can do to force the whole directory on one line?
Thanks
=A0
=A0
my $base_dir=3D"/home/Mumba/archive/$model_mon$dash$mon_name$yr /$model";
#
chdir ("$base_dir/$dat") || die "Sorry, couldn't cd: $!";
my @files =3D<$base_dir/$dat/*>;
foreach my $file (@files) {
   print "Catting $file\n" if $debug;
   system("/bin/cat @files > $model$cycle$grib_ext") or warn "Failed '$=
file': $! ($^E)";
}
#
system("/usr/bin/perl /usr/local/bin/grib2ctl.pl -verf $model$cycle$grib_ex=
t" > "$model$cycle$ctl_ext");
system("/usr/local/grads/bin/gribmap -i $model$cycle$ctl_ext -v -e");
#
opendir (BASE,"$base_dir/$model/$dat") || die "Cannot open BASE: $!";
while ($file =3D readdir(BASE)) {=20
  =A0 system("rm $file)\n") || warn "Having trouble deleting $file: $!"=
;
#   unlink($file)
}
closedir(BASE);

=0A
--0-1412090527-1226748122=:24762
Content-Type: text/html; charset=us-ascii

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?

Thanks

 

 

my $base_dir="/home/Mumba/archive/$model_mon$dash$mon_name$yr/$ model";
#
chdir ("$base_dir/$dat") || die "Sorry, couldn't cd: $!";
my @files =<$base_dir/$dat/*>;
foreach my $file (@files) {
   print "Catting $file\n" if $debug;
   system("/bin/cat @files > $model$cycle$grib_ext") or warn "Failed '$file': $! ($^E)";
}
#
system("/usr/bin/perl /usr/local/bin/grib2ctl.pl -verf $model$cycle$grib_ext" > "$model$cycle$ctl_ext");
system("/usr/local/grads/bin/gribmap -i $model$cycle$ctl_ext -v -e");
#
opendir (BASE,"$base_dir/$model/$dat") || die "Cannot open BASE: $!";
while ($file = readdir(BASE)) {
    system("rm $file)\n") || warn "Having trouble deleting $file: $!";
#   unlink($file)

}
closedir(BASE);





--0-1412090527-1226748122=:24762--

--===============1646407192==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1646407192==--

Re: Long directory structure on one line

am 15.11.2008 20:09:05 von Bill Luebkert

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 () { 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
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Long directory structure on one line

am 17.11.2008 12:20:06 von Brian Raven

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of zilore
mumba
Sent: 15 November 2008 11:22
To: activeperl@listserv.activestate.com
Subject: Long directory structure on one line

> 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?
> Thanks
>
>
> my $base_dir="/home/Mumba/archive/$model_mon$dash$mon_name$yr/$ model";

The problem (probably) lies in the code that you are not showing. If you
are still populating some of those variables by `date ...`, then they
will be terminated by a newline character. You should 'chomp' them, or
better still, use strftime.

Easy to check:

my $model_mon =`date "+%m"`;
print "model_mon='$model_mon'\n";

Compared to:

my $model_mon = srftime "%m", localtime;
print "model_mon='$model_mon'\n";

HTH

--
Brian Raven

------------------------------------------------------------ -----------------------------------------------
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Long directory structure on one line

am 18.11.2008 17:16:48 von zilore mumba

--===============0963460936==
Content-Type: multipart/alternative; boundary="0-230198913-1227025008=:64953"

--0-230198913-1227025008=:64953
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Bill,
Thanks very much for the assistance and sorry for not replying correctly.
And thanks also to Brian for pointing out ths source of my directory struct=
ure going on several lines, which was due to non use of CHOMP

You need to start replying properly.=A0 No HTML, just intersperse your
replies as I asked you previously and remove parts that are no longer
relevant.=A0 Reply to the list and not me directly with new problems.

So it's not part of base_dir then as we have it now ?=A0 Or is it ?=A0 It's
confusing.
=A0

Actually $model is part of $base_dir and inside $base_dir there=A0are files=
with names starting with $model (but slightly longer names)=A0
=A0
It works ok for me.=A0 See actual run at end.


And what happened then ?=A0 It still failed ?

  =A0 How do I replace "while () { print OUT $_; }" to
concatenate the files
=A0

I was actually trying to confirm if this does concatenation


Why would you want to replace it ?=A0 It's doing the concatenation of
the files now.=A0 As long as you open OUT prior to opening each file
and close OUT after all files are written to OUT, you're files are
then concatenated.
=A0

I have not been able to put together the assistance I received. When am thr=
ough and the script works I will send a message of thanks to indicate that =
it working well.
=0A
--0-230198913-1227025008=:64953
Content-Type: text/html; charset=us-ascii

Bill,

Thanks very much for the assistance and sorry for not replying correctly.

And thanks also to Brian for pointing out ths source of my directory structure going on several lines, which was due to non use of CHOMP

You need to start replying properly.  No HTML, just intersperse your
replies as I asked you previously and remove parts that are no longer
relevant.  Reply to the list and not me directly with new problems.

So it's not part of base_dir then as we have it now ?  Or is it ?  It's
confusing.

 


Actually $model is part of $base_dir and inside $base_dir there are files with names starting with $model (but slightly longer names) 

 

It works ok for me.  See actual run at end.


And what happened then ?  It still failed ?

    How do I replace "while (<IN>) { print OUT $_; }" to
concatenate the files

 


I was actually trying to confirm if this does concatenation



Why would you want to replace it ?  It's doing the concatenation of
the files now.  As long as you open OUT prior to opening each file
and close OUT after all files are written to OUT, you're files are
then concatenated.

 


I have not been able to put together the assistance I received. When am through and the script works I will send a message of thanks to indicate that it working well.





--0-230198913-1227025008=:64953--

--===============0963460936==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0963460936==--