[29231] in Perl-Users-Digest
Perl-Users Digest, Issue: 475 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 31 21:09:52 2007
Date: Thu, 31 May 2007 18:09:10 -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, 31 May 2007 Volume: 11 Number: 475
Today's topics:
[Long] Static classes, inheritance and base class funke <ts@dionic.net>
Re: [Long] Static classes, inheritance and base class f anno4000@radom.zrz.tu-berlin.de
Re: [Long] Static classes, inheritance and base class f <ts@dionic.net>
Re: A simple way to make a code folder available as a m <spamtrap@dot-app.org>
Re: Beyond Inside-Out <bik.mido@tiscalinet.it>
Re: contacting Alfred Reibenschuh, creator of (CPAN) PD <brian.d.foy@gmail.com>
Re: FAQ 8.11 How do I decode encrypted password files? <brian.d.foy@gmail.com>
Re: FAQ 8.28 How can I call backticks without shell pro <brian.d.foy@gmail.com>
Re: fork() and script execution afterwards <tom@snnap.net>
Re: fork() and script execution afterwards <tom@snnap.net>
Re: fork() and script execution afterwards <tom@snnap.net>
Re: How to find and replace something that is nested in <spamtrap@dot-app.org>
Re: How to find and replace something that is nested in <spamtrap@dot-app.org>
Re: How to find and replace something that is nested in <tadmc@augustmail.com>
Re: on my desk, as far as I can see <a24061@ducksburg.com>
Perl syntax <hslee911@yahoo.com>
Re: Prototypes and anonymous subroutines <nobull67@gmail.com>
Re: Prototypes and anonymous subroutines <nobull67@gmail.com>
Re: reinstall perl <spamtrap@dot-app.org>
Re: stumped by graphics display problem... (Alan Curry)
Re: stumped by graphics display problem... (Greg Bacon)
Re: stumped by graphics display problem... <socyl@987jk.com.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 31 May 2007 22:58:45 +0100
From: Tim S <ts@dionic.net>
Subject: [Long] Static classes, inheritance and base class funkery - or overriding module subroutines
Message-Id: <465f4516$0$645$5a6aecb4@news.aaisp.net.uk>
Hi
I'd be grateful of some feedback or different ways of solving this problem:
Scenario:
To write a suite of libraries for use by system maintenance scripts, eg
common logging, file-write handling (open tmp file, write to that, atomic
rename at end), database access etc. No problem fundamentally - done it
before. Want to improve and make this cut open source (last was at a
previous place of work).
Requirements:
a) Static classes (or modules) - each class is initialised once globally,
first by built in defaults then possibly reconfigured (typically once) at
run time from script arguments.
b) Make it easy for a 3rd party to override or add methods.
c) More complex classes may use the services of simpler classes, eg
everything uses the Log class.
d) Method overrides need to become visible to all users of the original
class as we do not want to edit the "use" line in every utiliser class.
e) No derived class can directly access the data in its SUPER class - public
methods only allowed, so this simplifies things.
eg:
Say we have classes:
Sys::Admin::Log
Sys::Admin::DB
and a script:
useraccounts which regenerates the passwd, group and shadow files on *nix.
But another site wants to override the message format in Sys::Admin::Log, so
derives Sys::Admin::Log::MySite, replacing one method, formatmsg($baremsg)
---------------
My solution so far (which works in test code):
Sys::Admin is a true base class to all others and provides a way for each
derived class to declare itself the "implementor" for its "root class" (my
terminology for the base class provider of that functionality). Sys::Admin
merely contains common helper methods.
When Sys::Admin::Log loads, it notes in a package hash in Sys::Admin that it
is the implementor class for "Sys::Admin::Log" (ie the base of the class
hierarchy that is responsible for logging functionality) and ditto for
Sys::Admin::DB (provider of DB services).
To use the class in another class or script we do:
##########
use Sys::Admin::Log;
sub L { return Sys::Admin::Log->load() }
L->log(L->INFO, 'Initialising ' . __PACKAGE__);
#########
Now our script might do:
#########
use Sys::Admin::Log::MySite;
use Sys::Admin::DB;
sub L { return Sys::Admin::Log::MySite->load() }
sub D { return Sys::Admin::DB->load() }
D->dosql("update table foo='bar' where wibble=1") or
L->log(L->FATAL, 'Bang');
#########
load() initialises the class the first time and everytime it returns the
implementor class name.
Thus L() just returns a class name - eg the literal 'Sys::Admin::Log'
OO style method calls work, eg L->log(..) which is fairly neat.
1) Sys::Admin::Log::MySite loads and notes (via Sys::Admin) that it is the
implementor for the root class "Sys::Admin::Log". It mostly relies on
Sys::Admin::Log's methods but overrides formatmsg()
2) Sys::Admin::DB loads and initialises Sys::Admin::Log. If it needs to log,
it's call to sub L { return Sys::Admin::Log->load() } actually returns the
literal 'Sys::Admin::Log::MySite' (from the hash in Sys::Admin) so it gains
the overridden methods via perl's normal @ISA search.
This is why the "object" is actually a sub - it can potentially change
depending on the order things are initialised - seems safer this way. It
was that or making the "object" a reference which makes the calling
semantics more ugly.
The test code is actually fairly elegant (but weird) in the way that derived
sub classes can be declared, but I'm wondering if I've missed a trick...
It's hard to describe further without getting even more verbose...
It seems rather complicated, and indeed, when we did a similar scheme at my
last workplace, we just made a suite of pure non OO modules. The difference
is, if we needed to change the functionality, we edited the base modules.
I'm looking for a way to give a basic core away, but allow other users to
customise the suite without having to hack around with the base
modules/classes - and thus make integrating updates more difficult.
In effect, I really want neat subroutine overriding on modules, but perl's
OO methodology seemed the only sensible way to achieve this.
Thoughts would be welcome. Sorry if this is not clear - it's not very easy
to describe in a couple of screen of text!
Cheers
Tim
------------------------------
Date: 31 May 2007 23:03:39 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: [Long] Static classes, inheritance and base class funkery - or overriding module subroutines
Message-Id: <5c92ibF2v9784U1@mid.dfncis.de>
Tim S <ts@dionic.net> wrote in comp.lang.perl.misc:
[...]
Sorry for the big snip, I only want to comment on one thing.
> In effect, I really want neat subroutine overriding on modules, but perl's
> OO methodology seemed the only sensible way to achieve this.
Have you tried the direct approach? If you want subroutine overriding
in modules, use subroutine overriding in modules, it may be powerful
enough. What I mean is that you *can* redefine a sub that is called
elsewhere, *after* "elsewhere" has been compiled and have "elsewhere"
use the new definition.
Suppose you have routine logger(), based on a central_logging_routine()
that defaults to an English format. Then, in some environment, someone
wants to use logger() in a German format, but continue to call logger()
for the purpose. This can be realized as follows:
sub logger {
central_logging_routine( shift);
}
sub central_logging_routine {
my $msg = shift;
print "Log Message: $msg\n";
}
logger( "Message one");
{
no warnings 'redefine';
*central_logging_routine = sub {
my $msg = shift;
print "Log-Meldung: $msg\n";
};
}
logger( "Meldung zwei");
That prints
Log Message: Message one
Log-Meldung: Meldung zwei
The effect is program-wide. After the change, everyone using logger()
will use the new format.
The example shows everything in one file, with the switch in behavior
at run-time. The switch might as well be performed in a loadable
file through "use" or "require" without first exercising the default
version.
I'm not sure if that is the behavior you want, but you may want to
consider it.
Anno
------------------------------
Date: Fri, 01 Jun 2007 00:21:26 +0100
From: Tim S <ts@dionic.net>
Subject: Re: [Long] Static classes, inheritance and base class funkery - or overriding module subroutines
Message-Id: <465f5876$0$644$5a6aecb4@news.aaisp.net.uk>
anno4000@radom.zrz.tu-berlin.de wrote:
> Tim S <ts@dionic.net> wrote in comp.lang.perl.misc:
>
> [...]
>
> Sorry for the big snip, I only want to comment on one thing.
>
>> In effect, I really want neat subroutine overriding on modules, but
>> perl's OO methodology seemed the only sensible way to achieve this.
>
> Have you tried the direct approach? If you want subroutine overriding
> in modules, use subroutine overriding in modules, it may be powerful
> enough. What I mean is that you *can* redefine a sub that is called
> elsewhere, *after* "elsewhere" has been compiled and have "elsewhere"
> use the new definition.
>
> Suppose you have routine logger(), based on a central_logging_routine()
> that defaults to an English format. Then, in some environment, someone
> wants to use logger() in a German format, but continue to call logger()
> for the purpose. This can be realized as follows:
>
> sub logger {
> central_logging_routine( shift);
> }
>
> sub central_logging_routine {
> my $msg = shift;
> print "Log Message: $msg\n";
> }
>
> logger( "Message one");
>
> {
> no warnings 'redefine';
> *central_logging_routine = sub {
> my $msg = shift;
> print "Log-Meldung: $msg\n";
> };
> }
>
> logger( "Meldung zwei");
>
> That prints
>
> Log Message: Message one
> Log-Meldung: Meldung zwei
>
> The effect is program-wide. After the change, everyone using logger()
> will use the new format.
>
> The example shows everything in one file, with the switch in behavior
> at run-time. The switch might as well be performed in a loadable
> file through "use" or "require" without first exercising the default
> version.
>
> I'm not sure if that is the behavior you want, but you may want to
> consider it.
>
> Anno
Ah yes - that is a pretty simple way to achieve overrides. I'd initially
discounted direct redefines as I'd erroneously considered
redefining "logger()" which I worried wouldn't affect the already exported
verions (I tend to EXPORT_OK if doing modules). But what you are doing is,
in effect, using logger() as a dispatcher to central_logging_routine()
which is never exported, so there is no problem.
Neat and simple and will work with OO and non OO modules.
Does mean that potential hooks need to be pre-declared (perhaps every public
method simply wraps an internal sub??), but may be beneficial because it is
clearer.
May have a problem with sub-classing a sub-class - but I'm not sure that is
ever going to be a practical problem...
Thanks for your ideas Anno. I going to think further on this.
Cheers
Tim
------------------------------
Date: Thu, 31 May 2007 16:48:15 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: A simple way to make a code folder available as a module
Message-Id: <m2tzts4t4g.fsf@local.wv-www.com>
Ilias Lazaridis <ilias@lazaridis.com> writes:
> if I place my folder "mycode" into
>
> C:/Perl/site/lib
>
> C:/Perl/site/lib/mycode
>
> the "use" statements have to be corrected to start with "mycode::"
>
> How can I avoid this?
Put your files into the correct folder. Perl maps package names directly
to folder names when searching for modules.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Fri, 01 Jun 2007 00:48:24 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Beyond Inside-Out
Message-Id: <q3ku535quhds1u3ocrpiftd2p7a62qjjnt@4ax.com>
On 31 May 2007 15:04:15 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>I think it would be disruptive to *report* the contents of this
>thread on perlmonks (or the other way around). I have pointed
>out on monks that there is this parallel discussion, not prominently
>but it's there. And, of course, in participating in both threads I'm
>ferrying information back and forth as opportunity allows or demands.
Well, it was not about reporting *everything*, but only significant
stuff, which AIUI is what you're already doing...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 31 May 2007 15:37:25 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: contacting Alfred Reibenschuh, creator of (CPAN) PDF-API2 ?
Message-Id: <310520071537254059%brian.d.foy@gmail.com>
In article <465ebd1f$0$8759$ed2619ec@ptn-nntp-reader02.plus.net>,
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> I've found (and I think fixed) a bug in this useful
> module:
>
> http://search.cpan.org/~areibens/PDF-API2-0.61/
>
> I've tried emailing my work (test cases, documentation and code changes) to
> the email address given here:
Have you submitted a bug to rt.cpan.org? That's a good place to put it.
:)
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Thu, 31 May 2007 15:32:59 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.11 How do I decode encrypted password files?
Message-Id: <310520071532598108%brian.d.foy@gmail.com>
In article <1180618533.798828.218060@p77g2000hsh.googlegroups.com>,
Brad Baxter <baxter.brad@gmail.com> wrote:
> On May 31, 3:03 am, PerlFAQ Server <b...@stonehenge.com> wrote:
> > 8.11: How do I decode encrypted password files?
> >
> > Seriously, you can't if they are Unix password files--the Unix password
> > system employs one-way encryption. It's more like hashing than
> > encryption. The best you can check is whether something else hashes to
> > the same string.
> That third sentence doesn't sound quite right to me. What about this:
>
> The best you can do is check whether something else hashes to the same
> string.
fixed, thanks.
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Thu, 31 May 2007 15:34:35 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.28 How can I call backticks without shell processing?
Message-Id: <310520071534353907%brian.d.foy@gmail.com>
In article <1180616552.861311.309730@g4g2000hsf.googlegroups.com>, Brad
Baxter <baxter.brad@gmail.com> wrote:
> On May 30, 3:03 pm, PerlFAQ Server <b...@stonehenge.com> wrote:
> > 8.28: How can I call backticks without shell processing?
> >
> > Note that if you're use Microsoft, no solution to this vexing issue is
> > even possible. Even if Perl were to emulate fork(), you'd still be
> > stuck, because Microsoft does not have a argc/argv-style API.
>
> s/use/using/;
> s/a argc/an argc/;
fixed and fixed, thanks.
If anyone knows how to excise the lame Windows comments and add
something useful, please let me know. :)
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Fri, 1 Jun 2007 10:14:54 +0930
From: "Tom Storey" <tom@snnap.net>
Subject: Re: fork() and script execution afterwards
Message-Id: <135ur0e61bvccdd@corp.supernews.com>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:loot535k7fsjnieh9bbr09do9er9lrh5lj@4ax.com...
> On Fri, 1 Jun 2007 00:08:53 +0930, "Tom Storey" <tom@snnap.net> wrote:
>
> >My question is, for each of the child processes that are spawned, I dont
see
> >"BEGIN" outputted to the screen.
>
> Well, only ONE "BEGIN" should be printed, since it is *before* the
> fork(). Or am I missing something?
That was my question, whether or not the child continues to execute from
where it forked in the parent, which seems as though it is the case.
>
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 1 Jun 2007 10:19:02 +0930
From: "Tom Storey" <tom@snnap.net>
Subject: Re: fork() and script execution afterwards
Message-Id: <135ur7usird8n23@corp.supernews.com>
<xhoster@gmail.com> wrote in message
news:20070531111545.141$FX@newsreader.com...
> Andrew Fedyashov <andrew.fedyashov@gmail.com> wrote:
> > On May 31, 5:38 pm, "Tom Storey" <t...@snnap.net> wrote:
> > > [...]
> > > If this is true, where I print BEGIN I could place my database code,
> > > and replace the for loop with a while loop that runs through each
> > > database record and forks a new child if neccessary.
> > >
> > > Thanks,
> > > Tom
> >
> > what you want is just the way fork() works.
>
> Yep.
>
> But one thing to look out for, is that the forked children may screw up
the
> parent's database connection. If the connection isn't needed after the
> fork, the parent should disconnect before it forks. It if it is needed,
it
> might still be best for the parent to disconnect and then reconnect after
> the forks, or if that is not convenient, than setting InactiveDestroy in
> the children may be necessary. If the children themselves need
> connections, they should initiate them after the fork, and *not* try to
use
> the one they inherited from the parent.
Hm excellent, thanks for the tips.
The children *will* need a database connection, but they wont need to use
the original connection which the parent uses.
I thought about disconnecting from the original database as the very first
line of code after forking, then establishing a new database connection for
the child to use as I figured there might be some issues.
In any case, I'll have to give it a try and see what happens.
Thanks again.
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 1 Jun 2007 10:20:22 +0930
From: "Tom Storey" <tom@snnap.net>
Subject: Re: fork() and script execution afterwards
Message-Id: <135urafetra1n85@corp.supernews.com>
"Tom Storey" <tom@snnap.net> wrote in message
news:135ur0e61bvccdd@corp.supernews.com...
>
> "Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
> news:loot535k7fsjnieh9bbr09do9er9lrh5lj@4ax.com...
> > On Fri, 1 Jun 2007 00:08:53 +0930, "Tom Storey" <tom@snnap.net> wrote:
> >
> > >My question is, for each of the child processes that are spawned, I
dont
> see
> > >"BEGIN" outputted to the screen.
> >
> > Well, only ONE "BEGIN" should be printed, since it is *before* the
> > fork(). Or am I missing something?
>
> That was my question, whether or not the child continues to execute from
> where it forked in the parent, which seems as though it is the case.
... in which case, yes I should only be seeing one BEGIN because that piece
of code only ever gets executed once. :-)
>
> >
> >
> > Michele
> > --
> > {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> > (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
>
>
------------------------------
Date: Thu, 31 May 2007 16:43:27 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to find and replace something that is nested inside something else?
Message-Id: <m2y7j44tcg.fsf@local.wv-www.com>
alainfri@gmail.com writes:
> Thank you for the fast reply, Xicheng. Actually I need a solution that
> would allow me to do this using the regular expressions provided by
> Windows Script Host or by .NET Framework.
Then you should ask your question in a group that discusses WSH or .NET.
Either that, or install ActiveState's WSH integration for Perl. :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 31 May 2007 17:11:19 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to find and replace something that is nested inside something else?
Message-Id: <m2abvk4s20.fsf@local.wv-www.com>
Sherm Pendley <spamtrap@dot-app.org> writes:
> alainfri@gmail.com writes:
>
>> Thank you for the fast reply, Xicheng. Actually I need a solution that
>> would allow me to do this using the regular expressions provided by
>> Windows Script Host or by .NET Framework.
>
> Then you should ask your question in a group that discusses WSH or .NET.
My apologies - I hadn't noticed that you *did* asked in those groups too.
Still, the principle is the same - if you don't want a Perl answer, you
shouldn't ask in a Perl group. Regexes are *not* generic - a regex that
works in WSH or .NET may not work in Perl, and vice-versa.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 31 May 2007 18:50:44 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to find and replace something that is nested inside something else?
Message-Id: <slrnf5unqk.v3i.tadmc@tadmc30.august.net>
["Followup-To:" header set to comp.lang.perl.misc.]
alainfri@gmail.com <alainfri@gmail.com> wrote:
> On May 31, 4:43 pm, Xicheng Jia <xich...@gmail.com> wrote:
>> On May 31, 8:57 am, alain...@gmail.com wrote:
>>
>> > I am not sure if this group is the right place for this question but
This is the right place to ask Perl questions.
>> If you are asking for Perl solutions, then here is one way to go:
>>
>> $string =~ s{<pre>(.*?)</pre>}{ mkCrtl($1) }egs;
>>
>> sub mkCrtl {
>> my $str = shift;
>> $str =~ s{<br>}{\n\r}g;
>> return "<pre>$str</pre>";
>>
>> }
> Actually I need a solution that
> would allow me to do this using the regular expressions provided by
> Windows Script Host or by .NET Framework.
Then you don't have a Perl question!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 31 May 2007 21:51:04 +0100
From: Adam Funk <a24061@ducksburg.com>
Subject: Re: on my desk, as far as I can see
Message-Id: <o2p3j4-0ji.ln1@news.ducksburg.com>
On 2007-05-31, barbara@bookpro.com wrote:
>>Nope, no geeks on ARK. No siree Bob.
>
> Yay, you proved that the person who said there are no geeks on ARK was
> wrong wrong wrongety wrong!
>
> Nobody said that, of course.
Well I sure as heck never claimed that!
> But just in case anyone ever does, Goggle will have archived your
> valuable proof to the contrary.
QED!!!1!
--
Is there any proof that English borrows words?? I mean, have we ever
given one back? Do we pay for a replacement if we break one? How does
this work? [Matthew L Martin, ark]
------------------------------
Date: 31 May 2007 16:40:01 -0700
From: James <hslee911@yahoo.com>
Subject: Perl syntax
Message-Id: <1180654801.844516.117100@i38g2000prf.googlegroups.com>
Need help to understand the following syntax.
Net::SSH::Perl package, in Channel.pm, line 142,
142: $r->{code}->( $c, $c->{$buf}, @{ $r->{extra} } );
in sub process_buffers,
sub process_buffers {
my $c = shift;
my($rready, $wready) = @_;
my %fd = (output => $c->{wfd}, extended => $c->{efd});
for my $buf (keys %fd) {
if ($fd{$buf} && grep { $fd{$buf} == $_ } @$wready) {
if (my $r = $c->{handlers}{"_${buf}_buffer"}) {
$r->{code}->( $c, $c->{$buf}, @{ $r->{extra} } );
}
else {
#warn "No handler for '$buf' buffer set up";
}
$c->{local_consumed} += $c->{$buf}->length
if $buf eq "output";
$c->{$buf}->empty;
}
}
if ($c->{rfd} && grep { $c->{rfd} == $_ } @$rready) {
my $buf;
sysread $c->{rfd}, $buf, 8192;
($buf) = $buf =~ /(.*)/s;
$c->send_data($buf);
}
}
TIA
James
------------------------------
Date: 31 May 2007 14:47:03 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Prototypes and anonymous subroutines
Message-Id: <1180648023.893415.88950@g4g2000hsf.googlegroups.com>
On May 31, 5:27 pm, gba...@hiwaay.net (Greg Bacon) wrote:
> In article <1180626699.280974.311...@w5g2000hsg.googlegroups.com>,
> Brad Baxter <baxter.b...@gmail.com> wrote:
>
> : So a couple of questions:
> :
> : 1. If prototypes are ignored for anonymous subroutines,
> : why be able to define them?
>
> You can make them work (see below), but maybe it was a speculative
> development path that deadended.
>
> : 2. Am I missing a calling convention that does not ignore
> : them?
>
> It's ugly, but consider
>
> $ perl -le 'BEGIN { *n = sub ($) { print @_ } } n(1,2)'
> Too many arguments for main::n at -e line 1, at end of line
> Execution of -e aborted due to compilation errors.
Have encountered obscure edge cases where I've used this sort of
thing. But they are rare.
I've also abused prototypes (in a similar way to the way sort() does)
as a poor-man's metadata by using the explicit prototype() function.
For an example see String::Interpolate.
------------------------------
Date: 31 May 2007 14:48:36 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Prototypes and anonymous subroutines
Message-Id: <1180648116.704132.54610@q69g2000hsb.googlegroups.com>
On May 31, 7:26 pm, Brad Baxter <baxter.b...@gmail.com> wrote:
> On May 31, 1:02 pm, "Skye Shaw!@#$" <skye.s...@gmail.com> wrote:
>
> > On May 31, 9:27 am, gba...@hiwaay.net (Greg Bacon) wrote:
>
> > > In article <1180626699.280974.311...@w5g2000hsg.googlegroups.com>,
> > > Brad Baxter <baxter.b...@gmail.com> wrote:
>
> > > : So a couple of questions:
> > > :
> > > : 1. If prototypes are ignored for anonymous subroutines,
> > > : why be able to define them?
>
> > Why bother defining them?
>
> Why bother documenting them? :-)
Because undocumented features a bad.
------------------------------
Date: Thu, 31 May 2007 16:54:27 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: reinstall perl
Message-Id: <m2ps4g4su4.fsf@local.wv-www.com>
JonL <bohat14@yahoo.com> writes:
> I realize that I will need to rebuild the cor perl using the prefix /
> usr/perl588 but is there are way of moving the modules over uithout
> recompiling them?
In my experience, I've never known a module to be location-aware. You
may be able to simply make a tarball of the module directory and move it
to the site_perl directory under your new prefix.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 31 May 2007 20:42:12 +0000 (UTC)
From: pacman@TheWorld.com (Alan Curry)
Subject: Re: stumped by graphics display problem...
Message-Id: <f3nbv4$b0g$1@pcls4.std.com>
In article <f3n312$evg$1@reader2.panix.com>,
kj <socyl@987jk.com.invalid> wrote:
>>> open my $IMG, '|-', 'display';
>>> print $IMG $gd->png;
>>>
>>> # display won't happen without this line!
>>> close $IMG;
>
>There's no shortage of fully graphical programs for viewing PNG
>files, but what I need is a viewer that I can control *entirely*
>from the keyboard. Are you saying that this would be too difficult
>to program?
(You can't quit the "display" program using the keyboard?)
What you're trying to do is separate closing the pipe from waiting on the
child process. The magical '|-' open ties those 2 actions together because
most of the time, having them tied together is convenient. If you want them
separate, you have to give up the magic and write it the long way with pipe()
and fork().
# Create a pipe and a child process
my ($rd, $wr);
pipe($rd, $wr) or die "pipe: $!\n";
my $pid=fork();
defined($pid) or die "fork: $!\n";
if(!$pid) {
# Child process reads from the pipe on stdin
open(STDIN, '<&', $rd);
# Child process doesn't write to the pipe, so close that end.
close($wr);
#{ exec 'display' } # I don't have "display"
{ exec 'xli', 'stdin' } # But I do have xli
die "exec: $!\n";
}
# Parent process doesn't read from the pipe, so close that end.
close($rd);
# Parent process feeds child the image
print $wr $imgdata;
# Because the pipe was not created with a magic open, this close just closes
# the pipe, and doesn't wait on the child process.
close($wr);
print "Press any key to continue... ";
ReadMode 'cbreak';
ReadKey( 0 );
ReadMode 'normal';
print "\n";
# The image viewer is still running, but our user is done looking at it.
# It won't die on its own; something must take it down. Hopefully it responds
# correctly to SIGTERM.
kill 15, $pid;
# Because the child process was not created with a magic open, perl will not
# clean up automatically when it dies. Without the following waitpid() we'd
# have a zombie process left over.
waitpid($pid,0);
print "All done\n";
--
Alan Curry
pacman@world.std.com
------------------------------
Date: Thu, 31 May 2007 22:43:23 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: stumped by graphics display problem...
Message-Id: <135ujsb7e9j1r8d@corp.supernews.com>
It seems like that code ought to be a lot simpler. I tried using mjd's
Secret Passage trick[*], but display never got the chance to start
because the pipe filled up while I tried to write the image data to it.
[*] <URL:http://perl.plover.com/LOD/199906.html#9>
Hmm.. what about a double-fork.. That gets pretty close, but it leaves
the display process running.
#! /usr/local/bin/perl
use warnings;
use strict;
open my $png, "<", "out.png" or die "$0: open: $!";
my $pid = open my $display, "|-";
die "$0: fork: $!" unless defined $pid;
if ($pid) {
print { $display } <$png>;
close $display or warn "$0: pipe exited $?";
}
else {
unless (fork) {
exec "display", "-" or die "$0: exec: $!";
}
exit 0;
}
print "Press enter to exit...\n";
my(undef) = scalar <>;
Without the curlies around $display in the parent's print, I get a
syntax error near "$png>" with perl v5.8.5. Weird.
Greg
--
The people cannot delegate to government the power to do anything
which would be unlawful for them to do themselves.
-- John Locke
------------------------------
Date: Thu, 31 May 2007 22:50:53 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: stumped by graphics display problem...
Message-Id: <f3njgd$gfk$1@reader2.panix.com>
In <f3nbv4$b0g$1@pcls4.std.com> pacman@TheWorld.com (Alan Curry) writes:
>In article <f3n312$evg$1@reader2.panix.com>,
>What you're trying to do is separate closing the pipe from waiting on the
>child process. The magical '|-' open ties those 2 actions together because
>most of the time, having them tied together is convenient. If you want them
>separate, you have to give up the magic and write it the long way with pipe()
>and fork().
Thanks, that worked like gangbusters.
># Create a pipe and a child process
>my ($rd, $wr);
>pipe($rd, $wr) or die "pipe: $!\n";
>my $pid=fork();
>defined($pid) or die "fork: $!\n";
>if(!$pid) {
> # Child process reads from the pipe on stdin
> open(STDIN, '<&', $rd);
> # Child process doesn't write to the pipe, so close that end.
> close($wr);
> #{ exec 'display' } # I don't have "display"
> { exec 'xli', 'stdin' } # But I do have xli
> die "exec: $!\n";
>}
I'm curious: why the curly brackets around the exec statement?
Thanks again,
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 475
**************************************