[32792] in Perl-Users-Digest
Perl-Users Digest, Issue: 4056 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 15 09:09:32 2013
Date: Tue, 15 Oct 2013 06:09:05 -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 Tue, 15 Oct 2013 Volume: 11 Number: 4056
Today's topics:
Re: Can't Perl Be Event Driven Too? <ben@morrow.me.uk>
Dumper <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Re: Dumper <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Re: multiple codepages <derykus@gmail.com>
Re: multiple codepages <rweikusat@mobileactivedefense.com>
Re: multiple codepages <ben@morrow.me.uk>
Re: multiple codepages <rweikusat@mobileactivedefense.com>
Re: multiple codepages <ben@morrow.me.uk>
Re: multiple codepages <derykus@gmail.com>
Re: multiple codepages <rweikusat@mobileactivedefense.com>
Re: sendmail not working - any alternatives? <John.Smith@invalid.com>
Re: sendmail not working - any alternatives? <ben.usenet@bsb.me.uk>
Re: using File::Spec effectively <cal@example.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 14 Oct 2013 17:06:10 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Can't Perl Be Event Driven Too?
Message-Id: <ichtia-m321.ln1@anubis.morrow.me.uk>
Quoth John Black <jblack@nospam.com>:
> I keep hearing about how Javascript / Node.js is great for web servers
> because its "event
> driven" and "non-blocking"... Statements like this are often made:
> "JavaScript happens to be
> a great fit for writing servers due to its event-driven nature."
>
> But how hard is it to use Perl for an event driven application like a
> web server. Seems to
> me you can just have a main thread processing the event requests. For
> each request, it
> spawns a thread to go off and do the work which reports back when done.
> The main event
> queueing thread is not "blocked" while the other threads are doing the
> work. Presto - event
> driven... What am I missing?
That's not 'event-driven', that's 'multi-threaded'.
See Twiggy and Corona on CPAN.
Ben
------------------------------
Date: Tue, 15 Oct 2013 15:36:07 +0300
From: George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Subject: Dumper
Message-Id: <l3jcqe$1l9c$1@news.ntua.gr>
# this works
use Data::Dumper; $Data::Dumper::Purity=1;
my $dmp;
my %hash1 = ('k1'=>'v1','k2'=>'v2');
$dmp = Data::Dumper::Dumper( \%hash1 );;
my $hash2 = eval $dmp; print Data::Dumper::Dumper($hash2);
# this is not
use strict; use warnings;
use Data::Dumper; $Data::Dumper::Purity=1;
my $dmp;
my %hash1 = ('k1'=>'v1','k2'=>'v2');
$dmp = Data::Dumper::Dumper( \%hash1 );;
my $hash2 = eval $dmp; print Data::Dumper::Dumper($hash2);
what I am doing wrong
------------------------------
Date: Tue, 15 Oct 2013 15:46:11 +0300
From: George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Subject: Re: Dumper
Message-Id: <l3jdda$1l9c$2@news.ntua.gr>
> # this works
>
>
>
> use Data::Dumper; $Data::Dumper::Purity=1;
> my $dmp;
> my %hash1 = ('k1'=>'v1','k2'=>'v2');
> $dmp = Data::Dumper::Dumper( \%hash1 );;
> my $hash2 = eval $dmp; print Data::Dumper::Dumper($hash2);
>
>
> # this is not
>
> use strict; use warnings;
> use Data::Dumper; $Data::Dumper::Purity=1;
> my $dmp;
> my %hash1 = ('k1'=>'v1','k2'=>'v2');
> $dmp = Data::Dumper::Dumper( \%hash1 );;
> my $hash2 = eval $dmp; print Data::Dumper::Dumper($hash2);
>
>
> what I am doing wrong
after scratching my head I conclude to this
my $hash2 = eval "our $dmp \$VAR1";
print Data::Dumper::Dumper($hash2);
do you think its ok;
------------------------------
Date: Mon, 14 Oct 2013 14:45:47 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: multiple codepages
Message-Id: <ff41c9f0-38c3-4864-a7ff-946fc70392da@googlegroups.com>
On Monday, October 14, 2013 3:47:09 AM UTC-7, Rainer Weikusat wrote:
> "C.DeRykus" <derykus@gmail.com> writes:
>
> > On Sunday, October 13, 2013 11:10:29 AM UTC-7, Rainer Weikusat wrote:
>
> >> "C.DeRykus" <derykus@gmail.com> writes:
>
> >> > On Tuesday, October 8, 2013 4:59:11 AM UTC-7, Rainer Weikusat wrote
...
>
> package FoosRUs;
>
>
>
> print MyFoo::add_something(14), "\n";
>
>
>
> my $x = SatanicLaughter->new($MyFoo::foo);
>
> *MyFoo::foo = \$x;
>
> my $blessed = \&Scalar::Util::blessed;
>
> *Scalar::Util::blessed = sub($) {
>
> if (caller() eq 'MyFoo') {
>
> print STDERR <<TT;
>
> The economy has been turned around in your area and the
>
> IT system of the contractor who pockets the money for
>
> providing what used to be this service doesn't (yet)
>
> work as you might have come to expect.
> Because this doesn't cost us anything, we apologize for
> any inconvenience caused.
> TT
> return;
> &$blessed;
> };
> print MyFoo::add_something(15), "\n";
package MyFoo;
our( $foo, $tmp);
sub add_something
{
die <<END if CORE::ref($foo);
*** Dear Supplicant:
Halleujah, there's been an exorcism of
potential satanic works. However, our
sanctuary remains in a state of siege.
Please ignore any screen output with
the mark of the beast. Any suggestions
to combat this ongoing threat will be
most gratefully received.
END
local $tmp = $foo;
$tmp += $_[0];
*foo = eval "\\$tmp";
return $foo;
}
--
Charles DeRykus
------------------------------
Date: Mon, 14 Oct 2013 23:11:48 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: multiple codepages
Message-Id: <87mwmblcyj.fsf@sable.mobileactivedefense.com>
"C.DeRykus" <derykus@gmail.com> writes:
> On Monday, October 14, 2013 3:47:09 AM UTC-7, Rainer Weikusat wrote:
[lots of 'codes' mutually breaking themselves]
> package MyFoo;
> our( $foo, $tmp);
>
> sub add_something
> {
> die <<END if CORE::ref($foo);
> *** Dear Supplicant:
> Halleujah, there's been an exorcism of
> potential satanic works. However, our
> sanctuary remains in a state of siege.
> Please ignore any screen output with
> the mark of the beast. Any suggestions
> to combat this ongoing threat will be
> most gratefully received.
> END
> local $tmp = $foo;
> $tmp += $_[0];
> *foo = eval "\\$tmp";
> return $foo;
> }
Insert
BEGIN {
*CORE::GLOBAL::die = sub {
print STDERR ("Lasciate ogne speranza, voi ch'intrate ...\n");
};
}
in front of the other code :-). But there are trivial workarounds for
this as well.
------------------------------
Date: Mon, 14 Oct 2013 23:09:05 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: multiple codepages
Message-Id: <1l6uia-7o61.ln1@anubis.morrow.me.uk>
Quoth "C.DeRykus" <derykus@gmail.com>:
> On Monday, October 14, 2013 3:47:09 AM UTC-7, Rainer Weikusat wrote:
> > "C.DeRykus" <derykus@gmail.com> writes:
> > > On Sunday, October 13, 2013 11:10:29 AM UTC-7, Rainer Weikusat wrote:
> > >> "C.DeRykus" <derykus@gmail.com> writes:
> >
> > >> > On Tuesday, October 8, 2013 4:59:11 AM UTC-7, Rainer Weikusat wrote
> ...
> >
> > package FoosRUs;
> >
> > print MyFoo::add_something(14), "\n";
> >
> > my $x = SatanicLaughter->new($MyFoo::foo);
> > *MyFoo::foo = \$x;
> > my $blessed = \&Scalar::Util::blessed;
> > *Scalar::Util::blessed = sub($) {
> > if (caller() eq 'MyFoo') {
> > print STDERR <<TT;
> > The economy has been turned around in your area and the
> > IT system of the contractor who pockets the money for
> > providing what used to be this service doesn't (yet)
> > work as you might have come to expect.
> > Because this doesn't cost us anything, we apologize for
> > any inconvenience caused.
> > TT
> > return;
> > &$blessed;
> > };
> > print MyFoo::add_something(15), "\n";
>
> package MyFoo;
> our( $foo, $tmp);
>
> sub add_something
> {
> die <<END if CORE::ref($foo);
> *** Dear Supplicant:
> Halleujah, there's been an exorcism of
> potential satanic works. However, our
> sanctuary remains in a state of siege.
> Please ignore any screen output with
> the mark of the beast. Any suggestions
> to combat this ongoing threat will be
> most gratefully received.
> END
require XSLoader;
XSLoader::load("List::Util", $List::Util::VERSION);
or, indeed, since List::Util is a well-behaved module,
delete $INC{"List/Util.pm"};
{
no warnings "redefine";
require List::Util;
}
> local $tmp = $foo;
> $tmp += $_[0];
> *foo = eval "\\$tmp";
> return $foo;
> }
Ben
------------------------------
Date: Tue, 15 Oct 2013 00:45:06 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: multiple codepages
Message-Id: <87hacjju2l.fsf@sable.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth "C.DeRykus" <derykus@gmail.com>:
>> On Monday, October 14, 2013 3:47:09 AM UTC-7, Rainer Weikusat wrote:
>> > "C.DeRykus" <derykus@gmail.com> writes:
>> > > On Sunday, October 13, 2013 11:10:29 AM UTC-7, Rainer Weikusat wrote:
>> > >> "C.DeRykus" <derykus@gmail.com> writes:
>> >
>> > >> > On Tuesday, October 8, 2013 4:59:11 AM UTC-7, Rainer Weikusat wrote
>> ...
>> >
>> > package FoosRUs;
>> >
>> > print MyFoo::add_something(14), "\n";
>> >
>> > my $x = SatanicLaughter->new($MyFoo::foo);
>> > *MyFoo::foo = \$x;
>> > my $blessed = \&Scalar::Util::blessed;
>> > *Scalar::Util::blessed = sub($) {
>> > if (caller() eq 'MyFoo') {
>> > print STDERR <<TT;
>> > The economy has been turned around in your area and the
>> > IT system of the contractor who pockets the money for
>> > providing what used to be this service doesn't (yet)
>> > work as you might have come to expect.
>> > Because this doesn't cost us anything, we apologize for
>> > any inconvenience caused.
>> > TT
>> > return;
>> > &$blessed;
>> > };
>> > print MyFoo::add_something(15), "\n";
>>
>> package MyFoo;
>> our( $foo, $tmp);
>>
>> sub add_something
>> {
>> die <<END if CORE::ref($foo);
>> *** Dear Supplicant:
>> Halleujah, there's been an exorcism of
>> potential satanic works. However, our
>> sanctuary remains in a state of siege.
>> Please ignore any screen output with
>> the mark of the beast. Any suggestions
>> to combat this ongoing threat will be
>> most gratefully received.
>> END
>
> require XSLoader;
> XSLoader::load("List::Util", $List::Util::VERSION);
>
> or, indeed, since List::Util is a well-behaved module,
>
> delete $INC{"List/Util.pm"};
> {
> no warnings "redefine";
> require List::Util;
> }
What purpose is List::Util supposed to have in here?
Something I don't really dare to suggest: A reference to the real
Scalar::Util::blessed could be captured in some variable which is not
accessible from outside the subroutine and then be used to invoke said
'real blessed'.
BEGIN {
my $blessed;
require Scalar::Util;
$blessed = \&Scalar::Util::blessed;
sub noli_disturbare_circulus_meos
{
print STDERR ($blessed->($_[0]) ? 'Nowdays, nothing but thinking global is really sensible!'
: 'Pitful attempt to move technology forward beyond 1956. Will have to wait until the old guard has died' , "\n");
}
}
*Scalar::Util::blessed = sub { return; };
noli_disturbare_circulus_meos(bless([], 'bla'));
------------------------------
Date: Tue, 15 Oct 2013 01:40:09 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: multiple codepages
Message-Id: <9gfuia-cc81.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
> Ben Morrow <ben@morrow.me.uk> writes:
> > Quoth "C.DeRykus" <derykus@gmail.com>:
> >> On Monday, October 14, 2013 3:47:09 AM UTC-7, Rainer Weikusat wrote:
> >> >
> >> > my $blessed = \&Scalar::Util::blessed;
> >> > *Scalar::Util::blessed = sub($) {
[...]
> > require XSLoader;
> > XSLoader::load("List::Util", $List::Util::VERSION);
[...]
>
> What purpose is List::Util supposed to have in here?
Try it and see :). (Hint: Scalar::Util and List::Util are both part of
the Scalar-List-Utils CPAN distribution, which only installs one .so
file.)
Of course, for real paranoia this could be augmented with something like
use Variable::Magic qw/cast wizard/;
my $blessed = \&Scalar::Util::blessed;
cast *Scalar::Util::blessed, wizard set => sub {
*{$_[0]} = $blessed;
warn <<HOLIERTHANTHOU;
*** Warning: a devilish attempt to subvert the sanctity of the
sacrament has been detected. This attempt has been thwarted.
HOLIERTHANTHOU
};
though even that won't do you any good in the long run...
Ben
------------------------------
Date: Mon, 14 Oct 2013 22:04:41 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: multiple codepages
Message-Id: <5f5fc277-bd5f-4a3c-911a-069acf19f5c1@googlegroups.com>
On Monday, October 14, 2013 3:09:05 PM UTC-7, Ben Morrow wrote:
> Quoth "C.DeRykus" <derykus@gmail.
> ...
>
> >
>
> > package MyFoo;
>
> > our( $foo, $tmp);
> > sub add_somethin
> require XSLoader;
>
> XSLoader::load("List::Util", $List::Util::VERSION);
>
> or, indeed, since List::Util is a well-behaved module,
>
>
> delete $INC{"List/Util.pm"};
>
> {
> no warnings "redefine";
>
> require List::Util;
> }
>
Indeed. Once Scalar-List-Utils was installed,
this sufficed (with both deletes needed,
combined shareable lib responsible, I guess ).
package MyFoo;
our( $foo, $tmp);
sub add_something {
delete $INC{"Scalar/Util.pm"};
delete $INC{"List/Util.pm"};
require Scalar::Util;
my $class = Scalar::Util::blessed( $foo);
die <<END if $class;
...
END
local $tmp = $foo;
$tmp += $_[0];
*foo = eval "\\$tmp";
return $foo;
}
--
Charles DeRykus
------------------------------
Date: Tue, 15 Oct 2013 12:15:39 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: multiple codepages
Message-Id: <8761syss2s.fsf@sable.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
>> Ben Morrow <ben@morrow.me.uk> writes:
>> > Quoth "C.DeRykus" <derykus@gmail.com>:
>> >> On Monday, October 14, 2013 3:47:09 AM UTC-7, Rainer Weikusat wrote:
>> >> >
>> >> > my $blessed = \&Scalar::Util::blessed;
>> >> > *Scalar::Util::blessed = sub($) {
> [...]
>> > require XSLoader;
>> > XSLoader::load("List::Util", $List::Util::VERSION);
> [...]
>>
>> What purpose is List::Util supposed to have in here?
>
> Try it and see :). (Hint: Scalar::Util and List::Util are both part of
> the Scalar-List-Utils CPAN distribution, which only installs one .so
> file.)
>
> Of course, for real paranoia this could be augmented with something like
>
> use Variable::Magic qw/cast wizard/;
>
> my $blessed = \&Scalar::Util::blessed;
> cast *Scalar::Util::blessed, wizard set => sub {
> *{$_[0]} = $blessed;
> warn <<HOLIERTHANTHOU;
> *** Warning: a devilish attempt to subvert the sanctity of the
> sacrament has been detected. This attempt has been thwarted.
> HOLIERTHANTHOU
> };
>
> though even that won't do you any good in the long run...
As soon as this moves into the domain of using custom extensions written
in C, the quest(ion) becomes a little useless: Provided that arbitrary
modifications can be made to the memory of the process, any concept of
'Perl semantics' evaporates.
Actually, I already consider the 'reload a file from the filesystem'
trick something similiar,
----------
package FoosRUs;
MyFoo::add_something(9);
*blessed = \&Scalar::Util::blessed;
mkdir('/tmp/Scalar');
open($fh, '>', '/tmp/Scalar/Util.pm');
print $fh <<'TT';
package Scalar::Util;
sub blessed($) {
caller() eq 'MyFoo' && do {
print STDERR <<XX;
Consider Phlebas, the Phoenician, a fortnight dead
Who once was handsome and tall just like you ...
XX
return;
};
goto &FoosRUs::blessed;
}
1;
TT
close($fh);
unshift(@INC, '/tmp');
my $x = SomethingElse->new($MyFoo::foo);
*MyFoo::foo = \$x;
print MyFoo::add_something(666), "\n";
----------
[quoted from memory and likely somewhat wrong]
but that's not really about what can or can't be done with Perl/perl
anymore.
------------------------------
Date: Tue, 15 Oct 2013 11:45:56 +0300
From: John <John.Smith@invalid.com>
Subject: Re: sendmail not working - any alternatives?
Message-Id: <ctvp59daavevupbse7qfr7a86rkdos0ev4@4ax.com>
I got a log from TEST.TXT is below. Everything seems ok but no email ever get to
any recipients (with valid email addresses not blahblah@whatever.com )
blahblah@whatever.com... Connecting to [127.0.0.1] via relay...
220 weblah.blah.net ESMTP Sendmail 8.13.8/8.13.8; Tue, 15 Oct 2013 10:27:06 +0200
>>> EHLO weblah.blah.net
250-weblah.blah.net Hello localhost.blah.net [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From:<blahblah@whatever.com> SIZE=85
250 2.1.0 <blahblah@whatever.com>... Sender ok
>>> RCPT To:<blahblah@whatever.com>
>>> DATA
250 2.1.5 <blahblah@whatever.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 r9F8R6bG272952 Message accepted for delivery
blahblah@whatever.com... Sent (r9F8R6bG272952 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 weblah.blah.net closing connection
------------------------------
Date: Tue, 15 Oct 2013 13:36:01 +0100
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: sendmail not working - any alternatives?
Message-Id: <0.c97847535c885d9b166d.20131015133601BST.87r4bmr9se.fsf@bsb.me.uk>
John <John.Smith@invalid.com> writes:
> I got a log from TEST.TXT is below. Everything seems ok but no email
> ever get to any recipients (with valid email addresses not
> blahblah@whatever.com )
Yes, the log looks fine, but there are countless reasons why the mail
does not get delivered once it's been accepted. Unless you have access
to the mail system's log files, you probably can't do much more than
keep complaining to the hosting company. In the end, you may well have
to switch.
<snip log>
--
Ben.
------------------------------
Date: Mon, 14 Oct 2013 13:06:55 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: using File::Spec effectively
Message-Id: <XKidnZWcD_hK08HPnZ2dnUVZ_oednZ2d@supernews.com>
On 10/10/2013 03:48 PM, Ben Morrow wrote:
[re-ordered, for thematic reasons]
>
> Quoth Cal Dershowitz <cal@example.invalid>:
>> 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?
>
> I don't know if you set them correctly. Who do you want to have
> permission to access these files?
>
> The permission number is in octal (shown by the leading 0), because it
> is divided into four groups of three bits. The first group is special
> permissions (setuid, setgid and sticky); the other three are read, write
> and execute/search permission for owner, group and other respectively.
> So 0755 (or 00755) on a directory is
>
> octal binary permission
> 0 0 setuid off
> 0 setgid off
> 0 sticky off
>
> 7 1 owner read on
> 1 owner write on
> 1 owner search on
>
> 5 1 group read on
> 0 group write off
> 1 group search on
>
> 5 1 other read on
> 0 other write off
> 1 other search on
>
> Ben
>
Thanks for your generous comment, Ben; I'll take this part of it up with
the other Ben upthread.
>>> 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?
>
> No, not at all. rootdir returns a string representing the root of the
> (a) filesystem; the fact that on Unix and Win32 this happens to be the
> same as the directory separator is just a coincidence (or, a consequence
> of the sensible design of the Unix path syntax).
>
> rootdir should never be used anywhere except at the front of a path.
ok
>
>> 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 would not recommend using File::Spec directly: it's rather verbose,
> and the class setup is confusing. If you really care about portable
> paths, I would recommend either File::Spec::Functions, or using
> Path::Class from CPAN instead.
>
> OTOH, I find that in general I can get away with sticking to /-separated
> paths relative to the current directory. These are valid on all
> currently-relevant OSs, and are much easier to deal with than trying to
> get File::Spec to behave.
>
> [snip: I don't know why you posted all that output, it didn't tell us
> anything useful.]
I have things set for extra verbosity, and there's still a lot of print
statements, as this architecture is rather fluid still. Apparently I
need it more than you do. I think a person might use both without
mucking it too badly. Is that naive?
>
>> $ 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;
>
> So, to start with, this is wrong. This is 'a path ending in a
> directory', so you want catdir. rootdir is not involved here.
I went with dir() from Path::Class.
>
>> print "path1 is $path_patch\n";
>> #mkdir
>> unless(-e $to or mkdir($to, 0755)) {
>> die "Unable to create $to\n";
>> };
>> my @files = <$path_patch*>;
>
> This is extremely confusing. $path_patch ends with a /, so this is a
> glob of all files in a directory, but that's not at all clear from the
> code. Probably if you want to be portable the best thing is to do
>
> my @file = glob catfile $path_patch, "*";
I couldn't for the life of me get anything like this to work.
>
> (assuming you import catfile from File::Spec::Functions). This gives you
> 'a complete path ending with a filename' where the filename is "*",
> which glob will then expand.
>
> OTOH you could just use readdir, or File::Slurp::read_dir, or
> Path::Class::Dir->children.
>
>> foreach $_ (@files) {
>> $_ =~ s/^$path_patch//;
>
> You cannot assume you can remove a directory name like this. Probably
> you want abs2rel with two arguments.
Kludge removed => better.
>
>> }
>> #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;
>
> my $from_path = catfile $path_patch, "$from$highest.$ext";
>
> There, isn't that clearer?
yes
>
>> foreach $_ (@files1) {
>> next if $_ =~ m/~$/; #no backup files copied
>> if ($_ =~ m/pm$/) {
>>
>> foreach $_ (@files1) {
>> next if $_ =~ m/~$/; #no backup files copied
>> if ($_ =~ m/css$/) {
>>
>> foreach $_ (@files1) {
>> next if $_ =~ m/~$/; #no backup files copied
>> if ($_ =~ m/tmpl$/) {
>
>
>> Q1 = shift; that is, is there something less-kludgy than pasting
>> together paths with what the method call of File::Spec rootdir() returns?
>
> Yes. Use the functions properly.
ok
>
>> 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.
>
> What did you try? The obvious answer would be
>
> if ($_ =~ m/(pm|css|tmpl)$/) {
>
Of course, thank you, I don't know why it didn't work when I was
fumbling around with it, so I spent a couple days with _Learning Perl_
in hand again, which gets to the matter elegantly.
I went ahead and re-wrote everything with Path:Class in addition to File
Spec, making particular use of dir() and file() of the former, and
File::Spec->splitpath of the latter:
$ perl hearts1.pl neptune ursula
knufjes are /home/fred/Documents/root/ pages
files are neptune5.pl~ neptune3.pl neptune9.html neptune3.pl~
neptune10.html neptune5.pl neptune6.pl neptune3.html neptune2.html
neptune6.pl~ neptune4.pl~ neptune7.html neptune8.html neptune1.pl
neptune4.pl neptune7.pl~ neptune2.pl neptune4.html neptune6.html
template_stuff neptune2.pl~ neptune5.html neptune7.pl neptune1.html
highest is 7
to is ursula
ts is /home/fred/Documents/root/pages/ursula/template_stuff
to_captions is ursula/template_stuff/captions
to_images is ursula/template_stuff/images
from_path is /home/fred/Documents/root/pages/neptune/neptune7.pl
to_path is /home/fred/Documents/root/pages/ursula/ursula1.pl
tpath is /home/fred/Documents/root/pages/ursula/template_stuff
$ cat hearts1.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use neptune1 qw( highest_number );
use Cwd;
use File::Basename;
use File::Spec;
use File::Copy;
use Path::Class;
my ($from, $to) = @ARGV;
my $halyard = "template_stuff";
my $images = "images";
my $captions = "captions";
my $current = cwd;
my @knufjes = File::Spec->splitpath( $current );
print"knufjes are @knufjes\n";
my $from_path = dir(@knufjes,$from);
opendir DIR, $from_path or die "cannot open dir $from_path: $!";
my @files = grep { $_ ne '.' && $_ ne '..' } readdir DIR;
closedir DIR;
print "files are @files\n";
my $ext = "pl";
my $highest = highest_number(\@files, $ext, $from);
print "highest is $highest\n";
#mkdirs
mkdir $to, 0755 or warn "couldn't make $to: $!\n";
say "to is $to";
my $ts = dir(@knufjes,$to, $halyard);
say "ts is $ts";
mkdir $ts, 0755 or warn "couldn't make $ts: $!\n";
my $to_captions = dir($to,$halyard,$captions);
say "to_captions is $to_captions";
mkdir $to_captions, 0755 or warn "couldn't make $to_captions: $!\n";
my $to_images = dir($to,$halyard,$images);
say "to_images is $to_images";
mkdir $to_images, 0755 or warn "couldn't make $to_images: $!\n";
my $from_path2 = file(@knufjes,$from,$from.$highest.".".$ext);
# copy
print "from_path is $from_path2\n";
my $to_path = file(@knufjes,$to,$to."1.".$ext);
print "to_path is $to_path\n";
copy( $from_path2, $to_path);
my $tpath = dir(@knufjes,$to,$halyard);
say "tpath is $tpath";
$
I like how a person can stuff the return from splitpath into any odd
little array, which I called knufjes, because I solicited a dutch word
from someone. Anyone know what it means? It sounds like finger food to me.
I solicited people for word families like Mr, Schwartz uses, got those
dutch words and a suggestion to use the planets, which I have found
helpful in getting this somewhat squared away. Likewise, boat parts
like $halyard that went through no fewer than 10 revisions, so it was a
good "word family" for reassembling with repitition, but now that it's
done, I wonder what a better term for $halyard might be in this expression:
my $ts = dir(@knufjes,$to, $halyard);
What I like about this syntax is that it is concise and the identifiers
within the method call to dir aren't littered with dir and and a bunch
of underscores, so as to make it wide.
What I like about $halyard is that it specifies "template_stuff" without
being $template_stuff, or having the word "template" in it at all, as
that is not informative within a template.
I like $to: informative, lexical, short.
What I don't like is that knufjes could be something off the Reeperbahn
for all I know, and $halyard doesn't match up to any other word family
now that the "sorting" is done, so it can go bye-bye.
my $ts = dir( ,$to, );
How would you fill out this syntax?
--
Cal
------------------------------
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 4056
***************************************