[32789] in Perl-Users-Digest
Perl-Users Digest, Issue: 4053 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 10 06:09:30 2013
Date: Thu, 10 Oct 2013 03:09:02 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 10 Oct 2013 Volume: 11 Number: 4053
Today's topics:
Re: using File::Spec effectively <cal@example.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 Oct 2013 02:31:12 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: using File::Spec effectively
Message-Id: <GOOdndHAnoJO7svPnZ2dnUVZ_hqdnZ2d@supernews.com>
On 10/09/2013 03:32 AM, Cal Dershowitz wrote:
> What one seems to have to do is build a path using catfile and append
> the system's representation of root. Is that what a person is supposed
> to do?
I'm trying to sort out these questions and do my own first edit,
snipping the code from the original post, but not the question.
I'd much rather come away from this discussion understanding File::Spec
than cling to the latest thing I've thrown at the rim.
I'm fairly convinced that this is original sin in the perl sense.
It doesn't involve a talking snake; it involves pasting together paths
in a kludgy-looking way.
> Fishing for comments in general from people who maybe have more than a
> week's exposure to this. Tomorrow, I'll try running this on a windows
> machine and see how badly it insults me.
$ cat lemon1.sh
#!/bin/bash
set -e
#echo "List of files:"
#ls -lA
perl spades5.pl $1 $2
$ bash lemon1.sh tiparos hummingbirds
rootdir is /
path1 is tiparos/
highest is 7
from_path is tiparos/tiparos7.pl
to_path is hummingbirds/hummingbirds1.pl
mast is hummingbirds/template_stuff
path to pm is tiparos/template_stuff/
base is Config1.pm
a is tiparos/template_stuff/Config1.pm
b is hummingbirds/template_stuff/Config1.pm
base is Config2.pm
a is tiparos/template_stuff/Config2.pm
b is hummingbirds/template_stuff/Config2.pm
base is MySubs1.pm
a is tiparos/template_stuff/MySubs1.pm
b is hummingbirds/template_stuff/MySubs1.pm
base is MySubs2.pm
a is tiparos/template_stuff/MySubs2.pm
b is hummingbirds/template_stuff/MySubs2.pm
base is MySubs3.pm
a is tiparos/template_stuff/MySubs3.pm
b is hummingbirds/template_stuff/MySubs3.pm
base is rad1.css
a is tiparos/template_stuff/rad1.css
b is hummingbirds/template_stuff/rad1.css
base is rebus1.tmpl>
> Thanks for your comment,
a is tiparos/template_stuff/rebus1.tmpl
b is hummingbirds/template_stuff/rebus1.tmpl
my path to caps is hummingbirds/template_stuff/captions
my path to images is hummingbirds/template_stuff/images
$ cd hummingbirds/
$ ls -l
total 8
-rw-r--r-- 1 fred automation 2482 Oct 10 01:41 hummingbirds1.pl
drwxr-xr-x 4 fred automation 4096 Oct 10 01:41 template_stuff
$ cd template_stuff/
$ ls -l
total 36
drwxr-xr-x 2 fred automation 4096 Oct 10 01:44 captions
-rw-r--r-- 1 fred automation 449 Oct 10 01:41 Config1.pm
-rw-r--r-- 1 fred automation 470 Oct 10 01:41 Config2.pm
drwxr-xr-x 2 fred automation 4096 Oct 10 01:41 images
-rw-r--r-- 1 fred automation 2113 Oct 10 01:41 MySubs1.pm
-rw-r--r-- 1 fred automation 1025 Oct 10 01:41 MySubs2.pm
-rw-r--r-- 1 fred automation 1933 Oct 10 01:41 MySubs3.pm
-rw-r--r-- 1 fred automation 2162 Oct 10 01:41 rad1.css
-rw-r--r-- 1 fred automation 56 Oct 10 01:41 rebus1.tmpl>
> Thanks for your comment,
$ cd ..
$ pwd
/home/fred/Documents/root/pages/hummingbirds
$ cd ..
$ pwd
/home/fred/Documents/root/pages
$ ls
about hockey links portabello spades3.pl ticket
chabot hummingbirds Merrill_Jensen quaternions spades3.pl~ tiparos
clover jesse micah ralph spades4.pl
contact keystone MySubs1.pm spades1.pl spades4.pl~
diamond lemon1.sh MySubs4.pm spades1.pl~ spades5.pl
FileSpec lemon1.sh~ MySubs4.pm~ spades2.pl spades5.pl~
hearts leprechaun pacific spades2.pl~ terminal
$ cat spades5.pl
#!/usr/bin/perl -w
use strict;
use MySubs4 qw( highest_number );
use Cwd;
use File::Basename;
use File::Spec;
use File::Copy;
my ($from, $to) = @ARGV;
my $dir = cwd;
my $rootdir = File::Spec->rootdir();
print "rootdir is $rootdir\n";
my $path_patch = $from.$rootdir;
print "path1 is $path_patch\n";
#mkdir
unless(-e $to or mkdir($to, 0755)) {
die "Unable to create $to\n";
};
my @files = <$path_patch*>;
foreach $_ (@files) {
$_ =~ s/^$path_patch//;
}
#print "files are @files\n";
my $ext = "pl";
my $highest = highest_number(\@files, $ext, $from);
print "highest is $highest\n";
my $from_path = $path_patch.$from.$highest.".".$ext;
print "from_path is $from_path\n";
my $to_path = $to.$rootdir.$to."1.".$ext;
print "to_path is $to_path\n";
copy( $from_path, $to_path);
my $halyard = "template_stuff";
#mkdir
my $mast = $to.$rootdir.$halyard;
print "mast is $mast\n";
unless(-e $mast or mkdir($mast, 0755)) {
die "Unable to create $to\n";
};
my $path_to_pm = $path_patch.$halyard.$rootdir;
print "path to pm is $path_to_pm\n";
my @files1 = <$path_to_pm*>;
#print "files1 are @files1\n";
foreach $_ (@files1) {
next if $_ =~ m/~$/; #no backup files copied
if ($_ =~ m/pm$/) {
my $base = basename($_);
print "base is $base\n";
my $a = $_;
print "a is $a\n";
my $b = $to.$rootdir.$halyard.$rootdir.$base;
print "b is $b\n";
copy($a, $b);
}
}
foreach $_ (@files1) {
next if $_ =~ m/~$/; #no backup files copied
if ($_ =~ m/css$/) {
my $base = basename($_);
print "base is $base\n";
my $a = $_;
print "a is $a\n";
my $b = $to.$rootdir.$halyard.$rootdir.$base;
print "b is $b\n";
copy($a, $b);
}
}
foreach $_ (@files1) {
next if $_ =~ m/~$/; #no backup files copied
if ($_ =~ m/tmpl$/) {
my $base = basename($_);
print "base is $base\n";
my $a = $_;
print "a is $a\n";
my $b = $to.$rootdir.$halyard.$rootdir.$base;
print "b is $b\n";
copy($a, $b);
}
}
# make captions amd images directories>
> Thanks for your comment,
my $path_to_caps = $to.$rootdir.$halyard.$rootdir."captions";
print "my path to caps is $path_to_caps\n";
my $path_to_images = $to.$rootdir.$halyard.$rootdir."images";
print "my path to images is $path_to_images\n";
unless(-e $path_to_caps or mkdir($path_to_caps, 0755)) {
die "Unable to create $to\n";
};
unless(-e $path_to_images or mkdir($path_to_images, 0755)) {
die "Unable to create $to\n";
};
$
I didn't get to my laptop today to try to sort this out with windows,
because I seem to have my hands full here.
>
> Thanks for your comment,
Q1 = shift; that is, is there something less-kludgy than pasting
together paths with what the method call of File::Spec rootdir() returns?
Q2 I've been reading the development in the alpaca book and was pretty
sure that I could create a regex that would know that I want to have an
or among pm css and tmpl, but I couldn't achieve as a lexical variable.
Instead I have 3 pretty fortranny-looking controls. They might be
cute as a first effort, but I'd like to see what an old perl pro might
write instead.
Q3) Do I set permissions correctly? Since I set them to 755, what
situations would I do as well? For example, I could grant others in the
group write priveleges. What number would that entail, and how is that
best represented in perl?
Thx for your comment.
--
Cal Dershowitz
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4053
***************************************