[30813] in Perl-Users-Digest
Perl-Users Digest, Issue: 2058 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 15 21:09:44 2008
Date: Mon, 15 Dec 2008 18:09:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 15 Dec 2008 Volume: 11 Number: 2058
Today's topics:
Re: a homework need help (David Combs)
Re: FAQ 9.4 How do I remove HTML from a string? <brian.d.foy@gmail.com>
Re: Noob trying to understand simple Perl grep statemen <ced@blv-sam-01.ca.boeing.com>
Perl# then Language# - Platform independence sln@netherlands.com
Re: Perl# then Language# - Platform independence <tim@burlyhost.com>
Re: Perl# then Language# - Platform independence sln@netherlands.com
Running END and/or DESTROY when you've been killed by a <bernie@fantasyfarm.com>
Re: Running END and/or DESTROY when you've been killed <smallpond@juno.com>
Re: Running END and/or DESTROY when you've been killed xhoster@gmail.com
Re: Running END and/or DESTROY when you've been killed bernie@fantasyfarm.com
Re: Running END and/or DESTROY when you've been killed bernie@fantasyfarm.com
Re: Running END and/or DESTROY when you've been killed <ced@blv-sam-01.ca.boeing.com>
Re: suggestions for tree data structure (David Combs)
Re: The single biggest STUPIDITY in Perl ... <brian.d.foy@gmail.com>
Re: The single biggest STUPIDITY in Perl ... <brian.d.foy@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Dec 2008 21:04:20 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: a homework need help
Message-Id: <gi6gok$7j3$2@reader1.panix.com>
In article <ghb7vq$u21$1@nntp.fujitsu-siemens.com>,
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
>Camel wrote:
>> I have no clue with my homework, can anyone help me?
>>
>> Three digits "1,2,3", how many 3-digit numbers can be made? print all the
>> numbers
>>
>> I know how to calculate the total numbers and using loop to print all the
>> numbers. The problem is how to write a generic program that takes any number
>> of digits. For example, if given "1,2,3,4,5" digits, you still can use your
>> program to print all the combinations of 5-digit numbers without modifing
>> it.
>
>The answer is: as many as there are permutations of the <n> digits.
>
Followed by stripping out any leftmost zeros.
David
------------------------------
Date: Mon, 15 Dec 2008 18:25:58 -0600
From: brian d foy <brian.d.foy@gmail.com>
To: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 9.4 How do I remove HTML from a string?
Message-Id: <151220081825588473%brian.d.foy@gmail.com>
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]
In article <gi5ai8$nrr$1@reader1.panix.com>, David Combs
<dkcombs@panix.com> wrote:
> >9.4: How do I remove HTML from a string?
#!/usr/bin/perl -p0777
> > s/<(?:[^>'"]*|(['"]).*?\1)*>//gs
>
> Since part of the job-description of a perl faq is to teach
> a bit of perl, about explaining how it works would be a
> nice addition.
This answer is on my list of answers to rewrite, but if you want to do
it for me, send me the patch. :) I'm not blowing this off, just not
getting to it right away.
This is probably one of the more frequently asked questions. It's not
only a Perl question because its answer is almost the same for anyone
trying to do it with a regex.
------------------------------
Date: Mon, 15 Dec 2008 17:44:38 -0800 (PST)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <076557d3-aad1-4dd8-8b47-1394f3d0ee37@k36g2000pri.googlegroups.com>
On Dec 15, 6:22 am, Dave Stratford <da...@orpheusmail.co.uk> wrote:
> In article
> <7fed4465-73c9-4b5d-859a-185fd9d06...@a26g2000prf.googlegroups.com>,
> C.DeRykus <c...@blv-sam-01.ca.boeing.com> wrote:
>
>
>
> > On Dec 13, 8:09 pm, gba...@hiwaay.net (Greg Bacon) wrote:
> > > In article <86skp05d7o....@blue.stonehenge.com>,
> > > Randal L. Schwartz <mer...@stonehenge.com> wrote:
>
> > > : I still regret inventing JAPHs, which encouraged obfuperl, and in
> > > : some sense was the motivation for Perl golf. All three items
> > > : today harm Perl's public perception more than they help, and I'm
> > > : sad for that.
>
> > > Don't be a puritan. Perl is fun, and that's great! Snobs who look
> > > down their noses at jam sessions aren't worth worrying about.
>
> > I agree totally. Dismissive comments are for snobs -- Perl brings fun
> > back to programming. And seriously, an "Obfuscated C Contest" or a
> > Perl "golf" contest is often
> > serendipitous because you're looking in a language's nooks and
> > crannies to explore its capabilities. At times the bugs and mis-
> > features of a languare are exposed; at others, you reveal how the
> > gears and gizmos work under the covers. The "Obfuscated C contest"
> > regularly attracts world class C programmers. Larry's won a couple of
> > times as I recall.
> > Just think.. Perl may have been the result of his mis-spent
> > youth :)
>
> That's all very well, and indeed amusing and fun in the right place.
> Unfortunately people do write obfuscated code in the wrong place and at
> the wrong time. Sadly, about four years ago, and after repeated warnings,
> I eventually had to sack someone who continued to write obfuscated code in
> our application programs. He was merely one of a team of five programmers
> working on the same system, all of whom at some point would have had to
> amend that code. There are people on that team now who were not in the
> company at the time, those programs are still being updated and amended,
> and it would have been grossly unfair to them, and the rest of the team,
> to have allowed him to continue to do so.
>
> Be careful, be sensible!
Good advice. But, obfuscated code can be written
in all the langugages I'm aware of. Clearly, there are
major benefits to exploration and a sense of fun with
language. No one here is advocating "golf" constructs
for production code.
Sadly, though, the "O" word is often hurled by language
zealots arguing their special agendas and attempting
to sway the uninformed. Perl 6 should help with that.
--
Charles DeRykus
------------------------------
Date: Mon, 15 Dec 2008 21:17:32 GMT
From: sln@netherlands.com
Subject: Perl# then Language# - Platform independence
Message-Id: <dfhdk45taplgdmdhm0313dflhcbhj58dfa@4ax.com>
Why isin't Perl platform independent?
For that matter, why does there not exist independence
from Language, from I/O, hardware, filesystems, OS's and anything
else that requires expertise that inherantly detracts
from development of pure code?
Why do we need trusses of dependencies at a cost of trillions of
dollars?
How can we evolve as a technical society when we keep going down
this path that is really a path of no return?
Are we just developing code to support these underlying dependencies
or will we ever move forward towards real problem solving?
sln
------------------------------
Date: Mon, 15 Dec 2008 13:28:34 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Perl# then Language# - Platform independence
Message-Id: <7_z1l.1001$a01.700@newsfe03.iad>
sln@netherlands.com wrote:
> Why isin't Perl platform independent?
Perl has to be compiled for that platform and support many things to do
that. Also, not all platforms support the same things. Why is it a
problem in your mind for Perl to work on so many platforms without all
of the hassles? Sounds like a good thing to me. What's your point
here? No one's forcing you to use Perl, and not everyone does.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Mon, 15 Dec 2008 21:47:31 GMT
From: sln@netherlands.com
Subject: Re: Perl# then Language# - Platform independence
Message-Id: <4ljdk4d1vsi58a3mghpebcif7dit03l4k1@4ax.com>
On Mon, 15 Dec 2008 13:28:34 -0800, Tim Greer <tim@burlyhost.com> wrote:
>sln@netherlands.com wrote:
>
>> Why isin't Perl platform independent?
>
>Perl has to be compiled for that platform and support many things to do
>that. Also, not all platforms support the same things. Why is it a
>problem in your mind for Perl to work on so many platforms without all
>of the hassles? Sounds like a good thing to me. What's your point
>here? No one's forcing you to use Perl, and not everyone does.
I'm thinking verbal commands like "Make the best case out of this..
Grab all the files I think I need and check if there is a black hole
is in there somewhere", "Also, get my laundry and send it to the cleaners",
"And while your at it find out what I did wrong on that nuclear fushion
metrics you got me yesterday".
Wrap it all up in a subroutine called Today, store it somewhere, then take
the rest of the day off..
sln
------------------------------
Date: Mon, 15 Dec 2008 14:20:08 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Running END and/or DESTROY when you've been killed by a signal
Message-Id: <u4bdk4tkprlph15bq686nf0r2hiu0ljbu3@library.airnews.net>
I have an app that uses a library that needs to clean up after itself when
the program exits. Right now I'm using an END block but I'm about to
change that to doing a mini-DESTROY block [basically, the only object
method at all will be the destroy method..:o)]. Mostly this is all working
fine, *except* -- when my app is killed by a signal the cleanup doesn't
happen. I certainly don't want to disable the signals [else the program
wouldn't be easily killable and it is supposed to be :o)], but I'm not sure
how to handle things. Do I make a signal handler that consists of nothing
more that sub { exit; } and will that make the signal still kill the
process BUT allow Perl to tidy-up on the way out [and if so, I guess I'd
have to assign that to a bunch of signals: INTR, HUP and TERM will probably
suffice, I think. Dunno if this'll work or not [I'm just trying it now,
but is there a cleaner way to do this [or, indeed, am I misunderstanding
why my END block isn't getting called]]. THANKS!
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Mon, 15 Dec 2008 12:09:24 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Running END and/or DESTROY when you've been killed by a signal
Message-Id: <364a0e58-6672-4b42-95d8-c4bddd48d13a@41g2000yqf.googlegroups.com>
On Dec 15, 2:20 pm, Bernie Cosell <ber...@fantasyfarm.com> wrote:
> I have an app that uses a library that needs to clean up after itself when
> the program exits. Right now I'm using an END block but I'm about to
> change that to doing a mini-DESTROY block [basically, the only object
> method at all will be the destroy method..:o)]. Mostly this is all working
> fine, *except* -- when my app is killed by a signal the cleanup doesn't
> happen. I certainly don't want to disable the signals [else the program
> wouldn't be easily killable and it is supposed to be :o)], but I'm not sure
> how to handle things. Do I make a signal handler that consists of nothing
> more that sub { exit; } and will that make the signal still kill the
> process BUT allow Perl to tidy-up on the way out [and if so, I guess I'd
> have to assign that to a bunch of signals: INTR, HUP and TERM will probably
> suffice, I think. Dunno if this'll work or not [I'm just trying it now,
> but is there a cleaner way to do this [or, indeed, am I misunderstanding
> why my END block isn't getting called]]. THANKS!
perl -e '$SIG{HUP}=sub{exit}; sleep 100; END {print "foo"}' &
[1] 30884
kill -HUP 30884
foo
[1]+ Done perl -e '$SIG{HUP}=sub{exit}; sleep 100;
END {print "foo"}'
Seems to work ok.
------------------------------
Date: 15 Dec 2008 20:25:21 GMT
From: xhoster@gmail.com
Subject: Re: Running END and/or DESTROY when you've been killed by a signal
Message-Id: <20081215152407.374$q4@newsreader.com>
Bernie Cosell <bernie@fantasyfarm.com> wrote:
> I have an app that uses a library that needs to clean up after itself
> when the program exits. Right now I'm using an END block but I'm about
> to change that to doing a mini-DESTROY block [basically, the only object
> method at all will be the destroy method..:o)].
Of there is not a "new" or something equivalent to it, then where is
the object to be DESTROYED coming from?
> Mostly this is all
> working fine, *except* -- when my app is killed by a signal the cleanup
> doesn't happen. I certainly don't want to disable the signals [else the
> program wouldn't be easily killable and it is supposed to be :o)], but
> I'm not sure how to handle things.
Did the signals get handled correctly with END but now aren't with DESTROY?
If so, why do you want to switch from the thing that works to the thing
that doesn't work? The solutions we propose might interact badly with
whatever that reason is, so it is best to know.
> Do I make a signal handler that
> consists of nothing more that sub { exit; } and will that make the signal
> still kill the process BUT allow Perl to tidy-up on the way out [and if
> so, I guess I'd have to assign that to a bunch of signals: INTR, HUP and
> TERM will probably suffice, I think.
This might be over-board, but when I've sometimes resorted to:
$_=sub {warn @_; exit} foreach values %SIG.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 15 Dec 2008 15:13:36 -0800 (PST)
From: bernie@fantasyfarm.com
Subject: Re: Running END and/or DESTROY when you've been killed by a signal
Message-Id: <e38f59e3-c229-41a4-b34a-e350d4ab7e72@q26g2000prq.googlegroups.com>
On Dec 15, 3:09=A0pm, smallpond <smallp...@juno.com> wrote:
> On Dec 15, 2:20 pm, Bernie Cosell <ber...@fantasyfarm.com> wrote:
>
> > I have an app that uses a library that needs to clean up after itself w=
hen
> > the program exits. ...Mostly this is all working
> > fine, *except* -- when my app is killed by a signal the cleanup doesn't
> > happen. ...Do I make a signal handler that consists of nothing
> > more that sub { exit; } and will that make the signal still kill the
> > process BUT allow Perl to tidy-up on the way out
> perl -e '$SIG{HUP}=3Dsub{exit}; sleep 100; END {print "foo"}' &
> [1] 30884
> kill -HUP 30884
> foo
> [1]+ =A0Done =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0perl -e '$SIG{HUP}=3D=
sub{exit}; sleep 100;
> Seems to work ok.
Indeed it does: the very experiment I was running here. And it is
pretty clean [in terms of the resulting perl code: just a bunch of =3Dsub
{exit}s. thanks!
/Bernie\
------------------------------
Date: Mon, 15 Dec 2008 15:17:58 -0800 (PST)
From: bernie@fantasyfarm.com
Subject: Re: Running END and/or DESTROY when you've been killed by a signal
Message-Id: <22656f9e-7bcb-4ff0-8674-16dfdbd8097b@t26g2000prh.googlegroups.com>
On Dec 15, 3:25=A0pm, xhos...@gmail.com wrote:
> Bernie Cosell <ber...@fantasyfarm.com> wrote:
> > I have an app that uses a library that needs to clean up after itself
> > when the program exits. =A0Right now I'm using an END block but I'm abo=
ut
> > to change that to doing a mini-DESTROY block [basically, the only objec=
t
> > method at all will be the destroy method..:o)].
>
> Of there is not a "new" or something equivalent to it, then where is
> the object to be DESTROYED coming from?
Oh, I was planning on just hacking the object system. In my current
routine, which returns a scalar, I though I'd change it to return
something like bless(\$returnvalue, "fakepackage");
and then I would define: sub fakepackage::DESTROY {do cleanup stuff}.
> Did the signals get handled correctly with END but now aren't with DESTRO=
Y?
> If so, why do you want to switch from the thing that works to the thing
> that doesn't work? =A0The solutions we propose might interact badly with
> whatever that reason is, so it is best to know.
Nope -- signals didn't work at all. Problem is that as I discovered
today [in debugging the mess] I need to DESTROY _not_ just when the
program exits but also when the vbl goes out of scope. This *seemed*
to work most of the time, until I got to debugging the library routine
with a program that accessed it in a loop instead of just once...:o)
> This might be over-board, but when I've sometimes resorted to:
>
> $_=3Dsub {warn @_; exit} foreach values %SIG.
Probably excessive. I *think* that INTR HUP and TERM will get
essentially all of the normal program-terminating signals. If the app
calling me gets a seg fault or something, my routine not cleaning up
will be the least of our troubles...:o)
Thanks!
/bernie\
------------------------------
Date: Mon, 15 Dec 2008 16:59:11 -0800 (PST)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Running END and/or DESTROY when you've been killed by a signal
Message-Id: <bbe39c78-be7c-4778-8bc8-6d2bbc808ebe@z28g2000prd.googlegroups.com>
On Dec 15, 11:20 am, Bernie Cosell <ber...@fantasyfarm.com> wrote:
> I have an app that uses a library that needs to clean up after itself when
> the program exits. Right now I'm using an END block but I'm about to
> change that to doing a mini-DESTROY block [basically, the only object
> method at all will be the destroy method..:o)]. Mostly this is all working
> fine, *except* -- when my app is killed by a signal the cleanup doesn't
> happen. I certainly don't want to disable the signals [else the program
> wouldn't be easily killable and it is supposed to be :o)], but I'm not sure
> how to handle things. Do I make a signal handler that consists of nothing
> more that sub { exit; } and will that make the signal still kill the
> process BUT allow Perl to tidy-up on the way out [and if so, I guess I'd
> have to assign that to a bunch of signals: INTR, HUP and TERM will probably
> suffice, I think. Dunno if this'll work or not [I'm just trying it now,
> but is there a cleaner way to do this [or, indeed, am I misunderstanding
> why my END block isn't getting called]]. THANKS!
uncaught signals will bypass END, DESTROY blocks..
sigtrap can do this for the signals you've mentioned
wanting to catch , eg,
use sigtrap handler => \&my_handler, normal-signals;
This'll pick up INT, HUP, TERM, PIPE but you can add
other signal groups, eg,
use sigtrap 'handler' => \&my_handler,
normal-signals, error-signals;
(perldoc -f sigtrap)
--
Charles DeRykus
------------------------------
Date: Mon, 15 Dec 2008 20:51:54 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: suggestions for tree data structure
Message-Id: <gi6g19$7j3$1@reader1.panix.com>
In article <7860b9ac-3bb9-4f52-b595-6c16b5b027fe@p2g2000prf.googlegroups.com>,
freesoft12@gmail.com <freesoft12@gmail.com> wrote:
>I have a file containing many paths (files/links/dirs) and to remove
>duplicate or redundant paths. I want to open the file and read each
>path in that file and create a directory tree from it. Next, I want to
>copy that directory tree extracted from the file and move it
>underneath another directory (preserve the hierarchy).
>
>For example, my file contains the following paths:
>
>/a/b/c
>/a/b
>/a/b/d
>
>In the first path, 'c' is a regular file. The second path can be
>ignored since it is already covered by the first path. In the third
>path, 'd' is a symbolic link that points to (say) ../e/f (a regular
>file).
>
>I want to move this directory tree underneath another directory, say /
>tmp. Hence I will have /tmp/a/b/c, /tmp/a/b/d -> /tmp/a/e/f.
>
>Can you suggest an efficient data structure to capture the directory
>tree information?
>
>Regards
>Joe
idea:
That standard depth-first-search algo for buildint a
topological-order tree -- do that, somehow.
Luckily, in the above example (and presumably the problem to
solve, generally), the paths all start at the same place.
When you get through you should have ONE tree that
encompasses all the paths.
Then you "simply" (dfs) read it out.
(Some work and also assembly required.)
David
------------------------------
Date: Mon, 15 Dec 2008 18:19:36 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: The single biggest STUPIDITY in Perl ...
Message-Id: <151220081819365556%brian.d.foy@gmail.com>
In article
<d8b8ba06-23f3-4897-b94f-9d3d9fbf9fd0@i20g2000prf.googlegroups.com>,
jps <jpsweden@gmail.com> wrote:
> On Dec 11, 8:32 pm, brian d foy <brian.d....@gmail.com> wrote:
> > I think there are a lot of candidates for "biggest" ...
>
>
> Hi Brian!
> Well -- I disagree!! :)
If you disagree that there are a lot of candidates for Perl's biggest
design mistake, then you just don't use Perl enough.
This is a question I ask a lot of people to plumb the depths of their
experience. If you can't list five things, you just haven't used enough
of the language yet:
http://stackoverflow.com/questions/282329/what-are-five-things-you-hate-
about-your-favorite-language
------------------------------
Date: Mon, 15 Dec 2008 18:22:10 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: The single biggest STUPIDITY in Perl ...
Message-Id: <151220081822104780%brian.d.foy@gmail.com>
In article
<dc5829e7-a726-4dfd-b9f9-0018c3a7439f@w39g2000prb.googlegroups.com>,
jps <jpsweden@gmail.com> wrote:
> Mannerly Perl syntax is:
> A) $x[0]->[1]
> or
> B) ${$x[0]}[1]
Well, the accepted idiom is to leave off the implied -> between
subscripts:
.
$x[0][1];
You only need the arrow when the thing to the left is not a subscript
(and is a reference):
$ref->[0][1];
Your problem with references might be that you are using them wrong. :)
------------------------------
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 2058
***************************************