[28439] in Perl-Users-Digest
Perl-Users Digest, Issue: 9803 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 4 14:06:13 2006
Date: Wed, 4 Oct 2006 11:05:17 -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 Wed, 4 Oct 2006 Volume: 10 Number: 9803
Today's topics:
A Camel in My Mind's Eye <thyorison@yahoo.com>
Archive::Zip - end up with empty file ... <lev.weissman@creo.com>
Re: Archive::Zip - end up with empty file ... <mritty@gmail.com>
Re: FAQ 5.2 (Was: inserting lines) <ced@blv-sam-01.ca.boeing.com>
Re: FAQ 5.2 <rvtol+news@isolution.nl>
Re: How to start Internet Explorer from Perl Script? <rvtol+news@isolution.nl>
Re: How to start Internet Explorer from Perl Script? <mritty@gmail.com>
Re: How to start Internet Explorer from Perl Script? <mark.clementsREMOVETHIS@wanadoo.fr>
Re: LWP and 302 redirects (reading news)
Re: LWP and 302 redirects <flavell@physics.gla.ac.uk>
perl and mysql: slow inserts with innodb rickyars@gmail.com
Re: Perl Async .10 xhoster@gmail.com
Re: Please help me pass an array from VBA to Perl and p <bik.mido@tiscalinet.it>
Re: Please help me pass an array from VBA to Perl and p <rvtol+news@isolution.nl>
Re: Problem running "cvs commit -m" inside a Perl scrip (Chris Mattern)
Revert inplace edit on HUP or full disk jgraber@ti.com
Re: Revert inplace edit on HUP or full disk <nobull67@gmail.com>
sorting array reference of hashes <user@example.net>
Re: Spliting values and reversing a hash <bik.mido@tiscalinet.it>
Re: Spliting values and reversing a hash <rvtol+news@isolution.nl>
Re: Spliting values and reversing a hash <bik.mido@tiscalinet.it>
Re: Spliting values and reversing a hash <peace.is.our.profession@gmx.de>
Re: Spliting values and reversing a hash <tzz@lifelogs.com>
Re: Spliting values and reversing a hash <ced@blv-sam-01.ca.boeing.com>
trap <shahrahulb@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Oct 2006 10:02:24 -0700
From: "Ray Eston Smith Jr" <thyorison@yahoo.com>
Subject: A Camel in My Mind's Eye
Message-Id: <1159981344.019387.101850@m73g2000cwd.googlegroups.com>
I'm just starting to learn Perl (I'm on page 65 of the camel book).
As yet I have nothing to contribute to Perl discussions, not even
intelligent questions. However, having obsessively studied Hamlet for
the past 13 years, I have discovered some interesting word-play
involvling the Perl mascot:
Hamlet
Do you see yonder cloud that's almost in shape of a camel?
Polonius
By the mass, and 'tis like a camel, indeed.
A camel? A cloud? Claudius? Where?
Hamlet
Would I had met my dearest foe in heaven
Or ever I had seen that day, Horatio!
My father, methinks I see my father.
If your father is your foe, I can see that he would be your dearest
foe, Hamlet, but he's not quite in heaven -- it sounds more like he's
on his way to heaven, going through purgatory:
Ghost
I am thy father's spirit,
Doom'd for a certain term to walk the night,
And for the day, confin'd to fast in fires
Till the foul crimes done in my days of nature
Are burnt and purg'd away.........
Let me get this straight, Hamlet::
Your father is like your Uncle Claudius.
Claudius (cloud-ius) is like a cloud that's like a camel.
The camel-cloud is floating in heaven.
You wish to see your dearest foe in heaven.
Then you see your father.
Is he in heaven? Or in purgatory?
Hamlet, where is your father?
Horatio
Oh where, my lord!
Hamlet
In my mind's eye, Horatio.
In your mind's eye? Or in purgatory? Or both?
Your father or your uncle? Or both?
Your dearest foe or a camel? Or both?
A camel in your mind's eye?
Hamlet
Why, what should be the fear?
I do not set my life at a pin's fee
So now you're a pin, Hamlet?
And there's a camel in your eye?
MATHEW, 19, 24. HOLY BIBLE in the King James version.
Jesus
And again I say unto you, it is easier for a camel to go through the
eye of a needle, than for a rich man to enter into the Kingdom of
Heaven
Some people misconstrue this biblical passage to mean that wealth is
evil. Actually, it means that some rich men can't get into heaven
because they value their worldly possessions more than their souls;
they value Circumstance more than Self. Being rich is not a sin; even
killing a brother to gain a kingdom is not an unforgiveable sin. But
the man who values an earthly kingdom more than his own soul is doomed
to fast in fires. Such a man is Claudius:
Claudius
What if this cursed hand
Were thicker than itself with brother's blood,
Is there not rain enough in the sweet heavens
To wash it white as snow? Whereto serves mercy
But to confront the visage of offense?
And what's in prayer but this two-fold force,
To be forestalled ere we come to fall,
Or pardon'd, being down? Then, I'll look up;
My fault is past. But, O! what form of prayer
Can serve my turn? 'Forgive me my foul murder'?
That can not be since I am still possess'd
Of those effects for which I did the murder,
My crown, mine own ambition, and my queen.
May one be pardon'd and retain the offense?
..........................................
Try what repentance can: what can it not?
Yet what can it, when one can not repent?
And such a man is Hamlet's father:
Horatio (to the Ghost)
Or if thou hast uphoarded in thy life
Extorted treasure in the womb of earth,
For which, they say, you spirits oft walk in death...
Hamlet's father is in purgatory by choice, because he refuses to leave
his "extorted treasure."
These two foolish old men (and Polonius too) are trying to go
camel-like through Hamlet's mind's eye.
Forget the camels -- what's happening to the poor needle?
Horatio (speaking of the ghost of Hamlet's father)
A mote it is to trouble the mind's eye.
Hamlet (after killing Polonius, whom he mistook for Claudius)
I do repent; but heaven hath pleas'd it so,
To punish me with this and this with me;
That I must be their scourge and minister.
Pity the poor camel-crammed needle; that scourge and minister;
purgatory personified.
By following a tenuous thread between three innocent words, camel, pin,
and eye, my imagination has traced Hamlet's father, his Uncle
Claudius, and the false steward Polonius going camel-like through the
purgatory in Hamlet's mind's eye. At this point, perhaps the reader
agrees with Horatio:
Horatio
'Twere to consider too curiously, to consider so.
Hamlet
No, faith, not a jot; but to follow him thither with modesty enough
and likelihood to lead it, as thus:
Before the age of Joe Camel, in the Elizabethan age, "camel" had just
one vivid connotation -- the biblical metaphor of the camel going
through the eye of the needle. The camel appears just four times in all
of Shakespeare's works; twice in Troilus and Cressida, once in
Richard II, and once in Hamlet.
TROILUS AND CRESSIDA
Panduros
Achilles! a drayman, a porter, a very camel.
Ajax (beating Thersites)
You cur!.
Thersites
Mars his idiot! Do, rudeness, do, camel, do, do.
Thersites
I say this Ajax -
.......
Has not so much wit -
.......
As will stop the eye of Helen's needle...
RICHARD II
Richard
It is as hard to come as for a camel
To thread the postern of a small needle's eye.
So the mere presence of the word "camel" is enough to send us in search
of the needle (or pin) and its eye (Hamlet's mind's eye). But must
our search lead us to Purgatory?
Horatio
There's no offence, my lord.
Hamlet
Yes, by Saint Patrick, but there is, Horatio,
And much offence, too...
A New Variorum Edition of Shakespeare, edited by Horace Howard Furness,
Hamlet, volume 1, New York, American Scholar Publications, INC, 1965,
first published in 1877, page 111:
136. Saint Patrick] TSCHISHWITZ: If Sh. had wished to be historically
correct, he would have made a Dane swear by St Ansgarius. But since the
subject concerned an unexpiated crime, he naturally thought of St
Patrick, who kept a Purgatory of his own. See The Honest Whore [pt 2,
I, I, p 330, Dodsley ed 1825, where the text reads, 'St Patrick, you
know keeps Purgatory,' and not as the learned German quotes, 'keeps
his Purgatory.' Ed]
There is a very personal clue that Hamlet/Shakespeare's mind was
Purgatory. In Stratford Guild Chapel there was a mural of Judgment Day.
Although the mural was daubed over with whitewash about the time
Shakespeare was born (in belated obedience to a government edict
against religious icons and images), I believe that young Will could
see the mural through the whitewash (or perhaps the whitewash was
temporarily removed for special occasions, such as secret midnight
Catholic Confirmations). The mural showed a group of sinners bound
together with hoops of steel (a chain) and being led toward the mouth
of hell. The mouth of hell (or purgatory) was set in what looked like a
giant porcupine head.
Gertrude (to Hamlet)
Forth at your eyes your spirits wildly peep,
And, as the sleeping soldiers in the alarm,
Your bedded hair, like life in excrements,
Starts up and stand an end.
Ghost (to Hamlet)
I could a tale unfold whose lightest word
Would harrow up thy soul, freeze thy young blood,
Make thy two eyes, like stars, start from their spheres,
Thy knotted and combined locks to part,
And each particular hair to stand on end,
Like quills upon the fretful porpentine.
I hope I have better luck than Hamlet with the Perl camel in my mind's
eye.
-Ray Eston Smith Jr thyorison@yahoo.com
------------------------------
Date: 4 Oct 2006 08:37:52 -0700
From: "MoshiachNow" <lev.weissman@creo.com>
Subject: Archive::Zip - end up with empty file ...
Message-Id: <1159976272.472676.314420@b28g2000cwb.googlegroups.com>
HI,
The code looks like:
my $fh = IO::File->new ("out.zip","w");
$zip->addFileOrDirectory($NAME);
$zip->addFileOrDirectory($NAME1);
$zip->addFileOrDirectory($NAME2);
.
.
$zip->writeToFileHandle ($fh);
I end up with empty file ...
Appreciate any ideas.
Thanks
------------------------------
Date: 4 Oct 2006 08:43:26 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Archive::Zip - end up with empty file ...
Message-Id: <1159976606.485570.252680@h48g2000cwc.googlegroups.com>
MoshiachNow wrote:
> The code looks like:
>
> my $fh = IO::File->new ("out.zip","w");
> $zip->addFileOrDirectory($NAME);
> $zip->addFileOrDirectory($NAME1);
> $zip->addFileOrDirectory($NAME2);
> .
> .
> $zip->writeToFileHandle ($fh);
Where did $zip come from?
Where did $NAME, $NAME1, $NAME2 come from?
What are the return values of all the addFileOrDirectory calls?
Please post a SHORT but COMPLETE script that demonstrates your errors.
Paul Lalli
------------------------------
Date: Wed, 4 Oct 2006 16:26:05 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: FAQ 5.2 (Was: inserting lines)
Message-Id: <J6MDnH.762@news.boeing.com>
Tad McClellan wrote:
> Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
>> I recently complained about the lack of alternate approaches to the FAQ
>> "How do I change one line in a file/delete a line in a file/insert a
>> line in the middle of a file/append to the beginning of a file?"
>
>
>> Here is my first attempt at a more complete answer. Comments are
>> invited.
>
>
>> You can use a Perl "one-liner" with command-line switches to modify
>> a file (see perlrun).
>
>
> And you can do it in a file-based program with the $^I variable,
> or with the -i command-line switch.
>
> If you want to do it in a program file rather than as a one-liner,
> then be sure to local()ize the special variables into an appropriate
> scope:
>
> { local @ARGV = qw/ fileA /; # same as the one-liner below
> $^I = '.bak';
> while ( <> ) {
> s/bar/baz/;
> }
> }
>
^^^^
I agree with the improvements but a reference to perlfaq 5's
'How can I use Perl's "-i" option from within a program' could
shorten the rather longish re-write :).
--
Charles DeRykus
------------------------------
Date: Wed, 4 Oct 2006 16:21:21 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: FAQ 5.2
Message-Id: <eg0n77.1a4.1@news.isolution.nl>
Uri Guttman schreef:
>> [atribution repaired] Ruud:
>>> my $text ; { local $/ ; $text = <> }
>
> anyhow that would be simpler as:
>
> my $text = do { local $/ ; <> }
AFAIK that would be using more memory.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 4 Oct 2006 16:23:51 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How to start Internet Explorer from Perl Script?
Message-Id: <eg0n78.1a4.1@news.isolution.nl>
Tutico schreef:
> a.. How to start Internet Explorer from Perl Script?
Why IE and not the user's default browser?
What have you tried already?
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 4 Oct 2006 08:22:40 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How to start Internet Explorer from Perl Script?
Message-Id: <1159975360.775092.243780@e3g2000cwe.googlegroups.com>
Tutico wrote:
> a.. How to start Internet Explorer from Perl Script?
The same way you start any external program. Any or all of these might
be what you're looking for.
perldoc -f system
perldoc -f exec
perldoc perlop (search for qx)
perldoc -f open
> b.. How to send key to surf web with same Internet Explorer?
Not sure I understand your question. You want to write a Perl program
that will automatically manipulate an existing Internet Explorer
process? As in, you want to be able to send data to the process and
have it show up in IE's address bar or on a form? Why?
Are you sure you don't just want to use WWW::Mechanize for automated
web browsing?
Paul Lalli
------------------------------
Date: Wed, 04 Oct 2006 18:28:58 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: How to start Internet Explorer from Perl Script?
Message-Id: <4523e144$0$27399$ba4acef3@news.orange.fr>
Paul Lalli wrote:
>> b.. How to send key to surf web with same Internet Explorer?
>
> Not sure I understand your question. You want to write a Perl program
> that will automatically manipulate an existing Internet Explorer
> process? As in, you want to be able to send data to the process and
> have it show up in IE's address bar or on a form? Why?
>
> Are you sure you don't just want to use WWW::Mechanize for automated
> web browsing?
As an addendum to this, if automating IE is, in fact, the requirement then
Win32::IE::Mechanize
is pretty handy. There is also Mozilla::Mechanize, but I have no
experience with this.
Mark
------------------------------
Date: Wed, 04 Oct 2006 15:23:21 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: LWP and 302 redirects
Message-Id: <JlQUg.6811$o71.6239@newsread3.news.pas.earthlink.net>
On 10/04/2006 03:19 AM, IanW wrote:
> Hi
>
> I'm having trouble with LWP and 302 redirects. I found the
> "$ua->requests_redirectable" parameter in the LWP documentation but it still
> doesn't work. Here's my code:
>
> use LWP::UserAgent;
> my $ua = new LWP::UserAgent;
> push @{ $ua->requests_redirectable },'POST';
> my $request = HTTP::Request->new(POST => 'http://blah.blah');
> $request->content_type('application/x-www-form-urlencoded');
> $request->content("LOGIN1=$action&Y=$Y&p=$P");
> my $resp = $ua->request($request);
>
> Any ideas what I'm doing wrong?
>
> Ian
>
>
This is from the HTTP specification at
ftp://ftp.isi.edu/in-notes/rfc2616.txt :
> If the 302 status code is received in response to a request other
> than GET or HEAD, the user agent MUST NOT automatically redirect the
> request unless it can be confirmed by the user, since this might
> change the conditions under which the request was issued.
If 'http://blah.blah' is a script that you wrote, you can return a 303
(or 307 ?) status. If not, you'll have to look at the returned headers
to figure out where to post the form.
--
paduille.4058.mumia.w@earthlink.net
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 4 Oct 2006 16:51:37 +0100
From: "Alan J. Flavell" <flavell@physics.gla.ac.uk>
Subject: Re: LWP and 302 redirects
Message-Id: <Pine.LNX.4.64.0610041635110.20829@ppepc87.ph.gla.ac.uk>
On Wed, 4 Oct 2006, Mumia W. (reading news) wrote:
> This is from the HTTP specification at
> ftp://ftp.isi.edu/in-notes/rfc2616.txt
>
> > If the 302 status code is received in response to a request other
> > than GET or HEAD, the user agent MUST NOT automatically redirect the
> > request unless it can be confirmed by the user, since this might
> > change the conditions under which the request was issued.
[ I note that this would be more at home on
comp.infosystems.www.authoring.cgi (beware the automoderation bot),
since there's now rather little Perl-specific about it.
But ho hum. ]
The behaviour of actual browsers is not necessarily in conformance
with RFC2616, unfortunately. I have the impression that some things
got a lot better in recent browser versions, as compared with the time
that I originally wrote this page
http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect
"Redirect in response to POST transaction".
But some users still use old browser/versions, and when you're
configuring a server for use on the WWW, you need to make some kind of
provision (if only to refuse service, but that's not very nice) if the
browser does not behave itself.
> If 'http://blah.blah' is a script that you wrote, you can return a
> 303 (or 307 ?) status. If not, you'll have to look at the returned
> headers to figure out where to post the form.
My recommendation would be to configure the user-advertised URL as a
proxy, which sends the POST transaction to the other URL, behind
the scenes, captures the result, and feeds it back (reformatted as
necessary) to the user. In that way, the browser has no idea what the
actual machinery is, and there's no need to care how well the browser
supports 30x redirection of POST request.
Disclaimer: due to tiredness I haven't analyzed in detail what the O.P
is trying to achieve overall. But the mention of 30x and POST
triggered these rather general comments.
Errata: A recent email rebuked me for writing as if "idempotent" was
synonymous with "not producing side effects". I knew that already,
and will be adjusting the wording to try to make that clear.
Hope that helps a bit.
------------------------------
Date: 4 Oct 2006 08:37:50 -0700
From: rickyars@gmail.com
Subject: perl and mysql: slow inserts with innodb
Message-Id: <1159976270.431517.221040@h48g2000cwc.googlegroups.com>
i'm trying to insert 500k rows from a text file into a innodb table and
it's taking a little over 4 hours.
would someone tell me what is wrong with this code? would someone show
me how to do a multi-value input in perl (e.g. 10k rows with single
insert statment)?
thanks,
-ricky
my $select_handle =
$dbh->prepare('SELECT agent_id, agent_fullname FROM agents WHERE
agent_shortname = ? AND RDEOUTPUT_rde_id = ?');
my $insert_handle =
$dbh->prepare('INSERT INTO actual VALUES
(DEFAULT,?,?,?,?,?,?,?,?,?)');
while (<$GTRUTH>) {
chomp;
my @gtruth = split;
# get FK: AGENTS_agent_id
$select_handle->execute($gtruth[3],$rde_id);
my ($AGENTS_agent_id, $agent_fullname) = $select_handle->fetchrow;
$insert_handle->execute(
$AGENTS_agent_id, # FK from agents
$rde_id, # FK from rdeoutput
$gtruth_line[0], # ground truth time
0, # target is DEAD
$gtruth_line[7], # move status
$gtruth_line[8] # action
);
}
------------------------------
Date: 04 Oct 2006 16:44:12 GMT
From: xhoster@gmail.com
Subject: Re: Perl Async .10
Message-Id: <20061004124554.177$Yu@newsreader.com>
"Todd English" <toddenglish@gmail.com> wrote:
> Thank you for the reply.
>
> > my hunch was that your problem occurred because you're deleting items
> > from the hash while iterating over it, but on second thought I'm not so
> > sure.
>
> I originally thought this as well, and had tried a couple of variants
> to the code I posted where I didn't mess with the proc hash until all
> procs had reported their return. But this didn't make any difference
> and upon further reflection I didn't think this was the case.
My original post on this topic apparently never showed up. The problem
seems to come from the "kill 9,..." in Async's sub DESTROY. An Async child
will inherit a copy of the objects to all of its older siblings from the
parent. When the child exits, it will kill all of it's older siblings.
Thus the program only works correctly if the children terminate in the same
order that they began, so that a younger child never has an extent older
sibling to kill out of order.
I have no idea why the kill is there, and getting rid of it makes the
problem go away.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 4 Oct 2006 15:19:00 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Please help me pass an array from VBA to Perl and populate it. Newbie at wits' end!
Message-Id: <n1d7i2d6a0soo2sv1sg02i57qss076aej2@4ax.com>
On 3 Oct 2006 13:37:19 -0700, david.f.jenkins@usa.net wrote:
>I can't execute an external program or shove files around, because of
>performance implications, mostly. I need a "sub" (but one written in
>Perl) that I can call from VBA.
(Un)fortunately I don't know enough VBA (namely, no VBA at all) to
address your question. My naive answer would be along the lines that
it's not possible, period. But indeed there may be some
framework/technology that allows this. Hope someone will know better.
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: Wed, 4 Oct 2006 16:30:08 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Please help me pass an array from VBA to Perl and populate it. Newbie at wits' end!
Message-Id: <eg0nq2.1a0.1@news.isolution.nl>
Michele Dondi schreef:
> david.f.jenkins:
>> I can't execute an external program or shove files around, because of
>> performance implications, mostly. I need a "sub" (but one written in
>> Perl) that I can call from VBA.
>
> (Un)fortunately I don't know enough VBA (namely, no VBA at all) to
> address your question. My naive answer would be along the lines that
> it's not possible, period. But indeed there may be some
> framework/technology that allows this. Hope someone will know better.
VBA can call members of libraries, at least .dll.
So if there would be a perllib.dll or such, it would be possible.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 04 Oct 2006 16:28:34 -0000
From: syscjm@sumire.eng.sun.com (Chris Mattern)
Subject: Re: Problem running "cvs commit -m" inside a Perl script
Message-Id: <12i7o9ihkru2i84@corp.supernews.com>
In article <1159809557.065409.111620@m7g2000cwm.googlegroups.com>,
Newshound wrote:
>Sorry, that was a typo on my part. I do actually have an escaped
>double-quote at the end in my script, like so:
>
>my $mesg = "\"This is a\\\nmulti-line log message.\""
>
First rule of posting the code you're working on: cut and paste it.
That way you don't make typos (or if you do, it's a typo in your
code and responders can correctly diagnose that problem).
Next up, two style pointers in posting to Usenet:
1) Don't top post. Put your reply to the post *below* the quote.
2) Don't quote sigs.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: 04 Oct 2006 11:32:33 -0500
From: jgraber@ti.com
Subject: Revert inplace edit on HUP or full disk
Message-Id: <yvnlknwxcri.fsf@famous02.dal.design.ti.com>
Are there any gotcha's on this demo script to
revert an inplace edit when catching a HUP signal,
or on a full disk error?
Is there a variable that holds the backup filename,
that would also handle format -i'dir/*.bak' ?
demo appears to filter correctly without HUP,
revert on catching kill -HUP,
revert on catching fake full disk.
On kill -KILL, demo leaves a backup file,
but not a filtered file.
run on linux like this:
% cp demo junk
% perl -i~ demo junk &
[1] 27622
% kill -HUP 27622
demo caught ' fake full disk', reverting by rename 'junk~' to 'junk' status (1=ok): 1, and quit now
#!/usr/local/bin/perl
use warnings;
use strict;
$SIG{HUP} = \&sig_hup_handler;
sub sig_hup_handler{
local $" = ' '; # $" is list sep
die "$0 caught '@_', reverting by rename '$ARGV$^I' to '$ARGV' status (1=ok): ",
rename( $ARGV . $^I, $ARGV),
", and quit now\n"; }
my $i = 0;
while(<>){
s/$/"# $i"/e; # add line number
print;
sleep 1 if ++$i < 10;
if (eof) {print "# last line\n";
$i = 0; # then send full disk error to sig_hup
sig_hup_handler($!) if not close ;
# sig_hup_handler(' fake full disk') if not 0;
}
}
--
Joel
------------------------------
Date: 4 Oct 2006 10:14:57 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Revert inplace edit on HUP or full disk
Message-Id: <1159982097.327804.264090@e3g2000cwe.googlegroups.com>
jgraber@ti.com wrote:
> Are there any gotcha's on this demo script to
> revert an inplace edit when catching a HUP signal,
> or on a full disk error?
>
> demo appears to filter correctly without HUP,
> revert on catching kill -HUP,
> revert on catching fake full disk.
>
> On kill -KILL, demo leaves a backup file,
> but not a filtered file.
The solution is not to use the inbuilt inplace edit mechanism that
renames at the start but rather to create the new file with a suffix
and then rename that over the original. On properly enginerred OSs the
process of renaming over an exisitng file is atomic so there is never
an instant when there's no file under the original name.
See also IO::AtomicFile
------------------------------
Date: Wed, 04 Oct 2006 13:50:19 -0400
From: monkeys paw <user@example.net>
Subject: sorting array reference of hashes
Message-Id: <4LCdnblcecT4ab7YnZ2dnUVZ_vqdnZ2d@insightbb.com>
I have an array of hashes like so:
$f = [ {
'file_name' => 'TakeTwo',
'id_type' => 'bill',
'id' => 'CA2005010A1',
},
{
'file_name' => 'steve',
'id_type' => 'bill',
'id' => 'CA2005000A3',
},
];
I want to sort by file_name.
I am trying this:
sort sort_by_filename @{$f};
sub sort_by_filename {
return $a->{file_name} cmp $b->{file_name}
}
This does not work. How would one do this??
------------------------------
Date: 4 Oct 2006 16:01:44 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Spliting values and reversing a hash
Message-Id: <jjf7i21u5etuo67v7sis6s1up4q2bp814r@4ax.com>
On Wed, 04 Oct 2006 13:53:56 +0200, Mirco Wahab
<peace.is.our.profession@gmx.de> wrote:
>Why did you choose the explicit form of:
Because I didn't choose it! Jokes apart...
> $rev{$_} .= ','x defined $rev{$_} . $k
...because I didn't thought of it. And I'm not golfing, in which case
the chances of picking it up would have been probably higher.
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: Wed, 4 Oct 2006 16:33:41 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Spliting values and reversing a hash
Message-Id: <eg0nq3.1a0.1@news.isolution.nl>
mlwollman schreef:
> I have a hash with key value pairs like:
> 1 => Chocolate,Vanilla,Rocky Road
> 2 => Strawberry,Vanilla, Pistachio
> 3 => Cookie Dough,Chocolate
> 4 => Strawberry,Pistachio
>
> And I need to transform it to:
> Chocolate => 1,3
> Vanilla => 1,2
> Rocky Road => 1
> Strawberry => 2,4
> Pistachio =>2,4
> Cookie Dough => 3
>
> What's a good, simple way to do that?
>
> I thought about using while each and changing the value to an array
> and foreach array element make a new has with the array element as a
> key and the old key join() any existing values, I think. I'm pretty
> confused now.
perl -MData::Dumper -wle '
my %in = (
1 => ["Chocolate", "Vanilla", "Rocky Road"],
2 => ["Strawberry", "Vanilla", "Pistachio"],
3 => ["Cookie Dough", "Chocolate"],
4 => ["Strawberry", "Pistachio"],
);
my %out;
for my $k (keys %in) {
for (@{$in{$k}}) {
$out{$_} .= $out{$_} ? ",$k" : $k;
}
}
print Dumper \%in, \%out;
'
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 4 Oct 2006 17:24:52 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Spliting values and reversing a hash
Message-Id: <5gk7i2lltg8pigjq29gv6lmkonk8ppacpt@4ax.com>
On Wed, 4 Oct 2006 16:33:41 +0200, "Dr.Ruud" <rvtol+news@isolution.nl>
wrote:
>perl -MData::Dumper -wle '
> my %in = (
> 1 => ["Chocolate", "Vanilla", "Rocky Road"],
> 2 => ["Strawberry", "Vanilla", "Pistachio"],
> 3 => ["Cookie Dough", "Chocolate"],
> 4 => ["Strawberry", "Pistachio"],
> );
> my %out;
> for my $k (keys %in) {
> for (@{$in{$k}}) {
> $out{$_} .= $out{$_} ? ",$k" : $k;
> }
> }
> print Dumper \%in, \%out;
>'
Funnily enough you chose exactly the other way around what I did, i.e.
arrayrefs for the input and strings for the output.
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: Wed, 04 Oct 2006 17:36:21 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: Spliting values and reversing a hash
Message-Id: <eg0kli$2o7$1@mlucom4.urz.uni-halle.de>
Thus spoke Michele Dondi (on 2006-10-04 16:01):
> On Wed, 04 Oct 2006 13:53:56 +0200, Mirco Wahab
>>Why did you choose the explicit form of:
> Because I didn't choose it! Jokes apart...
Right, .. of course ... ;-)
>> $rev{$_} .= ','x defined $rev{$_} . $k
> ...because I didn't thought of it. And I'm not golfing, in which case
> the chances of picking it up would have been probably higher.
Yeah, I was so into it this afternoon ;-)
I made even a version (all strings), where
the input strings draw light onto the
algorithm, its shadow containing the
control output ...
(... but really, that's enough for now ...)
Regards
M.
( maybe someone has a funnier idea )
------ [cut here] 8< -----------
use strict;
use warnings;
use Data::Dumper;
my %h = (
4 => 'Strawberry,Pistachio',
3 => 'Cookie Dough,Chocolate',
1 => 'Chocolate,Vanilla,Rocky Road',
2 => 'Strawberry,Vanilla, Pistachio'); # <--light source ends here
@_=%h;%h=(),($_="@_")
=~s/\s//g,s/(\d+)
([^\d]+)/$h{$_}
.=','x defined
($h{$_}).$1
for(split
',',$2)
/egx
# <-- shadow starts here
;print
Dumper
\%h;%h = @_;
print Dumper \%h;
------------------------------
Date: Wed, 04 Oct 2006 12:34:42 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Spliting values and reversing a hash
Message-Id: <g69u02kyr8d.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 3 Oct 2006, mlwollman@gmail.com wrote:
> I have a hash with key value pairs like:
> 1 => Chocolate,Vanilla,Rocky Road
> 2 => Strawberry,Vanilla, Pistachio
> 3 => Cookie Dough,Chocolate
> 4 => Strawberry,Pistachio
>
> And I need to transform it to:
> Chocolate => 1,3
> Vanilla => 1,2
> Rocky Road => 1
> Strawberry => 2,4
> Pistachio =>2,4
> Cookie Dough => 3
Try Tie::Hash::TwoWay (I wrote it) on CPAN, which implements two-way
hash lookups between keys and values. It may simplify this job for
you if you have to do it repeatedly.
Ted
------------------------------
Date: Wed, 4 Oct 2006 16:56:53 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Spliting values and reversing a hash
Message-Id: <J6MF2s.8Bt@news.boeing.com>
John W. Krahn wrote:
> attn.steven.kuo@gmail.com wrote:
>> John W. Krahn wrote:
>>> for my $key ( keys %hash ) {
>>> for my $flavour ( @{ delete $hash{ $key } } ) {
>>> push @{ $hash{ $flavour } }, $key;
>>> }
>>> }
>> If I recall correctly, it isn't a good idea to delete
>> and add keys to a hash while iterating over it.
>
> "for my $key ( keys %hash )" creates a list of the hash keys in memory and any
> modifications to %hash inside the loop won't affect the contents of that list.
>
> perldoc -f delete
^^^^^^
ITYM perldoc -f keys:
The returned values are copies of the original keys
in the hash, so modifying them will not affect the
original hash. Compare "values".
--
Charles DeRykus
------------------------------
Date: 4 Oct 2006 08:28:02 -0700
From: "perlperl" <shahrahulb@gmail.com>
Subject: trap
Message-Id: <1159975682.794301.255580@b28g2000cwb.googlegroups.com>
I generate SNMP trap frequently on my hosts
Is there a perl script i can write to receive the SNMP traps?
i m using perl 5.6.1 (cannot upgrade to 5.8 due to restrictions)
I found this useful
http://search.cpan.org/~hardaker/NetSNMP-TrapReceiver-5.0301/TrapReceiver.pm
but,
1) will it work on perl 5.6.1
2) I installded the above module on windows, but couldnot find the file
snmptrapd.conf
is it a part of Net::SNMP module, do i need to install that module also
------------------------------
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 V10 Issue 9803
***************************************