Long directory structure on one line

--===============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 [at] files =3D<$base_dir/$dat/*>;
foreach my $file ( [at] files) {
=A0=A0 print "Catting $file\n" if $debug;
=A0=A0 system("/bin/cat [at] 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)) {
=A0=A0=A0 system("rm $file)\n") || warn "Having trouble deleting $file: $!"=
;
#=A0=A0 unlink($file)
}
closedir(BASE);

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

<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Perl Users,</DIV>
<DIV>Firstly my apologies for my very elementary knowledge of Perl.</DIV>
<DIV>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.</DIV>
<DIV>The problem is $base_dir, which is supposed to be</DIV>
<DIV>/home/Mumba/archive/11-November08/ukmo/20081115 is being put on several lines as</DIV>
<DIV>/home/Mumba/archive/11</DIV>
<DIV>-</DIV>
<DIV>November08</DIV>
<DIV>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.</DIV>
<DIV>Is there some trick I can do to force the whole directory on one line?</DIV>
<DIV>Thanks</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>my $base_dir="/home/Mumba/archive/$model_mon$dash$mon_name$yr/$ model";<BR>#<BR>chdir ("$base_dir/$dat") || die "Sorry, couldn't cd: $!";<BR>my [at] files =<$base_dir/$dat/*>;<BR>foreach my $file ( [at] files) {<BR>   print "Catting $file\n" if $debug;<BR>   system("/bin/cat [at] files > $model$cycle$grib_ext") or warn "Failed '$file': $! ($^E)";<BR>}<BR>#<BR>system("/usr/bin/perl /usr/local/bin/grib2ctl.pl -verf $model$cycle$grib_ext" > "$model$cycle$ctl_ext");<BR>system("/usr/local/grads/bin/gribmap -i $model$cycle$ctl_ext -v -e");<BR>#<BR>opendir (BASE,"$base_dir/$model/$dat") || die "Cannot open BASE: $!";<BR>while ($file = readdir(BASE)) { <BR>    system("rm $file)\n") || warn "Having trouble deleting $file: $!";<BR>#   unlink($file)<BR>
}<BR>closedir(BASE);<BR><BR></DIV></td></tr></table><br>


--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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1646407192==--
zilore mumba [ Sa, 15 November 2008 12:22 ] [ ID #1977177 ]

Re: Long directory structure on one line

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
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Bill Luebkert [ Sa, 15 November 2008 20:09 ] [ ID #1977178 ]

RE: Long directory structure on one line

From: activeperl-bounces [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] On Behalf Of zilore
mumba
Sent: 15 November 2008 11:22
To: activeperl [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Brian Raven [ Mo, 17 November 2008 12:20 ] [ ID #1977413 ]

Re: Long directory structure on one line

--===============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=A0=A0 How do I replace "while (<IN>) { 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=0A=0A
--0-230198913-1227025008=:64953
Content-Type: text/html; charset=us-ascii

<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Bill,</DIV>
<DIV>Thanks very much for the assistance and sorry for not replying correctly.</DIV>
<DIV>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<BR></DIV>
<DIV>You need to start replying properly.  No HTML, just intersperse your<BR>replies as I asked you previously and remove parts that are no longer<BR>relevant.  Reply to the list and not me directly with new problems.<BR><BR>So it's not part of base_dir then as we have it now ?  Or is it ?  It's<BR>confusing.</DIV>
<DIV> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV>Actually $model is part of $base_dir and inside $base_dir there are files with names starting with $model (but slightly longer names) </DIV>
<DIV> </DIV></BLOCKQUOTE>
<P dir=ltr>It works ok for me.  See actual run at end.<BR><BR><BR>And what happened then ?  It still failed ?<BR><BR>    How do I replace "while (<IN>) { print OUT $_; }" to<BR>concatenate the files</DIV>
<P dir=ltr> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr style="MARGIN-RIGHT: 0px">I was actually trying to confirm if this does concatenation<BR></DIV></BLOCKQUOTE>
<P dir=ltr style="MARGIN-RIGHT: 0px"><BR>Why would you want to replace it ?  It's doing the concatenation of<BR>the files now.  As long as you open OUT prior to opening each file<BR>and close OUT after all files are written to OUT, you're files are<BR>then concatenated.</DIV>
<P dir=ltr style="MARGIN-RIGHT: 0px"> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P dir=ltr style="MARGIN-RIGHT: 0px">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.<BR></DIV></BLOCKQUOTE></td></tr></table><br>


--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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0963460936==--
zilore mumba [ Di, 18 November 2008 17:16 ] [ ID #1977513 ]
Perl » gmane.comp.lang.perl.active-perl » Long directory structure on one line

Vorheriges Thema: Problem with Perl on Win Srvr
Nächstes Thema: Perlex - truncated CGI parameter data under stress