[23651] in Perl-Users-Digest
Perl-Users Digest, Issue: 5858 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 25 21:06:01 2003
Date: Tue, 25 Nov 2003 18:05:24 -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 Tue, 25 Nov 2003 Volume: 10 Number: 5858
Today's topics:
a simple thread testing program produces some very stra <im_not_giving_it_here@i_hate_spam.com>
Re: ActiveX component cannot create object <jwillmore@remove.adelphia.net>
Re: Assigning split to a list: undefined values? <bmb@ginger.libs.uga.edu>
Re: aternative grouping and map, deuglification (Sara)
execute debugger commands at startup <yshtil@cisco.com>
Executing php from with a perl script <johnm@aiamail.com>
Re: Executing php from with a perl script <usenet@morrow.me.uk>
IPC::Sharable <pkruminsREMOVETHIS@inbox.lv>
Re: module selction <jwillmore@remove.adelphia.net>
Re: newbie <STDIN> question Default@IO_Error_1011101.xyz
Re: Performance problem on SunOS 5.8 <jwillmore@remove.adelphia.net>
perl 5.6 multi byte (Sulla)
Re: Perl Editor <Paul@Hovnanian.com>
Regex matching question <stremitz@consultant.com>
Re: Regex matching question <abigail@abigail.nl>
Re: Regex matching question <zoooz@gmx.de>
Re: Regex matching question <krahnj@acm.org>
Re: Regex matching question (Sam Holden)
rename hash-key ? <pilsl_usenet@goldfisch.at>
Re: rename hash-key ? <pinyaj@rpi.edu>
Re: system() never returns, how to kill it? <asdf@asdf.com>
Re: trying to understand fork and wait (John)
Re: trying to understand fork and wait <usenet@morrow.me.uk>
Re: trying to understand fork and wait <jwillmore@remove.adelphia.net>
Re: undif as if it is 0 <emschwar@pobox.com>
Re: undif as if it is 0 <syscjm@gwu.edu>
Re: undif as if it is 0 <eddhig22@yahool.com>
Re: undif as if it is 0 <syscjm@gwu.edu>
Re: undif as if it is 0 <REMOVEsdnCAPS@comcast.net>
Unexpected tell() result <dwilga-MUNGE@mtholyoke.edu>
Re: Unexpected tell() result <usenet@morrow.me.uk>
Re: Unexpected tell() result (Malcolm Dew-Jones)
Re: unpack query (Anno Siegel)
Re: unpack query <usenet@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 26 Nov 2003 01:11:44 +0000
From: Asfand Yar Qazi <im_not_giving_it_here@i_hate_spam.com>
Subject: a simple thread testing program produces some very strange results: could you please tell me what the problem is?
Message-Id: <bq0ucb$7r6$1@newsg2.svr.pol.co.uk>
#!/usr/local/bin/perl -w
package Thread_Maker;
use strict;
sub new()
{
my $proto = shift();
my $class = ref($proto) || $proto;
my $self = [];
bless($self, $class);
return $self;
}
sub joinall()
{
my $self = shift;
foreach my $thread (@$self) {
print("Joining thread\n");
$$thread->join();
}
}
sub add(\@\&@)
{
my ($self, $funcref, @args) = @_;
my $tmpthread = threads->new($funcref, @args);
push(@$self, \$tmpthread);
}
1;
package main;
use Config;
use threads;
use threads::shared;
use Gtk;
use strict;
$Config{useithreads} or die "Recompile Perl with threads to run this
program.";
my $a : shared = 0;
sub sub1($\$)
{
my ($sleeptime, $var) = @_;
sleep($sleeptime);
++$$var;
}
sub printer(\$)
{
my ($var) = @_;
my $oldvar = $var;
while($$var != 2) {
while($$var == $oldvar) {}
$oldvar = $$var;
print('Variable = ', $$var, "\n");
};
print("Now exiting\n");
}
my $tmaker = new Thread_Maker;
$tmaker->add(\&printer, \$a);
$tmaker->add(\&sub1, 1, \$a);
$tmaker->add(\&sub1, 2, \$a);
$tmaker->joinall();
--OUTPUT--
Variable = 0
Joining thread
Variable = 1
Variable = 2
Now exiting
Joining thread
Joining thread
Scalars leaked: 1
Scalars leaked: 1
Scalars leaked: 1
--END OUTPUT--
What's with the 'Scalars leaked: 1' stuff?
--
http://www.it-is-truth.org/
------------------------------
Date: Wed, 26 Nov 2003 01:45:16 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: ActiveX component cannot create object
Message-Id: <20031125204515.53d0f50d.jwillmore@remove.adelphia.net>
On Tue, 25 Nov 2003 03:40:32 GMT
"David Jameson" <david@digiportal.com> wrote:
> From some experiments I have performed, it appears that this problem
> is due to MISSING registry entries.
> I've managed to put a few of the appropriate entries back in (by
> looking at my older machine where everything is working) and have
> gotten past the original error message (ActiveX component cannot
> create object) to a new message "The server module cannot be found"
>
> Clearly this means that the classID was now found but there's still
> something missing that's causing it to not be able to invoke
> PerlSE.DLL properly.
>
> Any ideas?
<snip - because WHOLE thread doesn't need to be re-posted>
Visit ActiveState's web site. There is a knowledge base there.
I thinking you *are* using the ActiveState build of Perl (you never
mentioned in either post) :-)
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Grandpa Charnock's Law: You never really learn to swear until
you learn to drive.
------------------------------
Date: Tue, 25 Nov 2003 15:13:05 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Assigning split to a list: undefined values?
Message-Id: <Pine.A41.4.58.0311251506180.16534@ginger.libs.uga.edu>
On Mon, 24 Nov 2003, Brad Baxter wrote:
> That isn't what I would have expected from reading this in perldoc -f
> split:
>
> If LIMIT is unspecified or zero, trailing
> null fields are stripped (which potential users of
> "pop" would do well to remember)
My apologies. I did also see this:
When assigning to a list, if LIMIT is omitted, Perl
supplies a LIMIT one larger than the number of
variables in the list, to avoid unnecessary work.
But when I tried out code like the following last night, I got it wrong
and confused myself. Will try to improve. :-)
1 #!/usr/local/bin/perl
2 use strict;
3 use warnings;
4
5 my $line = "1 2\n";
6
7 my ($node1, $node2, $node3) = split " ", $line;
8 my @x = split " ", $line;
9
10 print "$node1-$node2-$node3\n";
11 print join('-', @x), "\n";
1-2-
1-2
Regards,
Brad
------------------------------
Date: 25 Nov 2003 15:46:00 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: aternative grouping and map, deuglification
Message-Id: <776e0325.0311251546.a4878a7@posting.google.com>
gbacon@hiwaay.net (Greg Bacon) wrote in message news:<vs733ioshhni01@corp.supernews.com>...
> In article <776e0325.0311250819.7fa75087@posting.google.com>,
> Sara <genericax@hotmail.com> wrote:
>
> : [...]
> : I'm trying to find lines with a certain starting word like
> :
> : @a = map /^((CAT|DOG).+)$/, @a;
>
> If you're trying to find matches for a pattern, use Perl's grep
> operator:
>
> $ cat try
> #! /usr/local/bin/perl
>
> my @a = (
> 'CAT 4',
> 'DOG 3',
> 'CAT 6',
> 'CAT 9',
> 'BIRD 4',
> 'DOG 13',
> 'MOUSE 2',
> );
>
> @a = grep /^(CAT|DOG)\b/, @a;
>
> print "[$_]\n" for @a;
>
> $ ./try
> [CAT 4]
> [DOG 3]
> [CAT 6]
> [CAT 9]
> [DOG 13]
>
> $
>
> : [...]
>
> See the perlfunc manpage's documentation of grep for more information.
>
> Hope this helps,
> Greg
DUH!! Good suggestion sometimes I can't see the forest for the trees :)
Happy T-Day!
G
------------------------------
Date: Tue, 25 Nov 2003 17:06:20 -0800
From: "Yuri Shtil" <yshtil@cisco.com>
Subject: execute debugger commands at startup
Message-Id: <1069808906.934751@sj-nntpcache-3>
Hi
The GNU debugger gdb has an excellent feature that allows to place the
debugger commands in a file (.gdbinit) and have them executed by the
debugger at startup.
This way one can set various options, breakpoints etc thus saving time on
typing.
I wonder if something like that is possible with perldb. The .perldb file
can only contain perl code, not debugger commands.
Any idea anyone?
Yuri.
------------------------------
Date: Tue, 25 Nov 2003 14:04:57 -0600
From: "John Michael" <johnm@aiamail.com>
Subject: Executing php from with a perl script
Message-Id: <vs7dfa396k1p22@corp.supernews.com>
I know perl and can write the script. What I want to do is to be able to
grab a page, pass it to php if it has the php extension, get the
results(html) and then send it to the browser. Is it possible?
I saw this bit of code on a server that seems to execute php. Don't know
what it means, but it gave me the idea.
#!/bin/bash
export SCRIPT_NAME=${PATH_TRANSLATED##${DOCUMENT_ROOT}}
export SCRIPT_FILENAME=$PATH_TRANSLATED
/usr/bin/php
Right now I have a program that protects a members area. IT runs ssi and it
delivers all of the html docs, images and videos. I am sending my own
headers using nph, but I want to be able to do the same with php without
having to write the php code to go with my program.
Any ideas or thoughts would be greatly appreciated.
Thanks
John Michael
------------------------------
Date: Tue, 25 Nov 2003 20:27:29 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Executing php from with a perl script
Message-Id: <bq0dvh$lb8$2@wisteria.csv.warwick.ac.uk>
"John Michael" <johnm@aiamail.com> wrote:
> I know perl and can write the script. What I want to do is to be able to
> grab a page, pass it to php if it has the php extension, get the
> results(html) and then send it to the browser. Is it possible?
>
> I saw this bit of code on a server that seems to execute php. Don't know
> what it means, but it gave me the idea.
>
> #!/bin/bash
> export SCRIPT_NAME=${PATH_TRANSLATED##${DOCUMENT_ROOT}}
> export SCRIPT_FILENAME=$PATH_TRANSLATED
> /usr/bin/php
Well, the obvious thing to try is translating this into Perl <untested>:
($ENV{SCRIPT_NAME} = $ENV{PATH_TRANSLATED}) =~ s/^$ENV{DOCUMENT_ROOT}//;
$ENV{SCRIPT_FILENAME} = $ENV{PATH_TRANSLATED};
system "/usr/bin/php";
# or maybe exec would be better
Ben
--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
ben@morrow.me.uk
------------------------------
Date: 25 Nov 2003 23:14:34 GMT
From: Peteris Krumins <pkruminsREMOVETHIS@inbox.lv>
Subject: IPC::Sharable
Message-Id: <Xns943FC802EDA1whitesuneapollolv@130.133.1.4>
To keep statistics which are collected by
parent and child processes I decided to
take the advantage of shared memory (shm) and
share some variables (scalars and hashes).
The parent forks lots of child processes (depending
on load 100 to 1000 an hour), which
increase some counters and create hash data structures.
The problem is that after couple of hours looking
at `ipcs' output I see no shm is released, new memory
is allocated and the list grows larger and larger.
I am afraid to run out of memory.
Once an hour the program received USR1 signal
upon which it dumps the statistics to a file and
(imo) frees memory.
the program structure is like following:
my %stats;
my $stats_handle;
my $stats_handle_chkd;
my $stats_handle_rej;
my ($stats_rcvd, $stats_chkd, $stats_rej);
# ...
# make variables shared
#
$stats_handle_chkd = tie $stats_chkd, 'IPC::Shareable',
undef, { destroy => 1 };
$stats_handle_rej = tie $stats_rej, 'IPC::Shareable',
undef, { destroy => 1 };
$stats_handle = tie %stats, 'IPC::Shareable',
undef, { destroy => 1 };
($stats_rcvd, $stats_chkd, $stats_rej) = (0,0,0);
# ...
# loop until <something> {
# ...
$stats_rcvd++;
# ...
fork
here increase $stats_chkd, $stats_rej,
and do smth with hash, for example
$stats{'in'}{'user_one'}++;
exit child
# }
# and the signal USR1 handler just:
#
sub usr1_handler {
# dump data to file
# ...
($stats_rcvd, $stats_chkd, $stats_rej) = (0,0,0);
%stats = ();
}
P.Krumins
------------------------------
Date: Wed, 26 Nov 2003 01:56:17 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: module selction
Message-Id: <20031125205617.716bb99f.jwillmore@remove.adelphia.net>
On Tue, 25 Nov 2003 14:10:52 +1100
Alison <allidance2002@hotmail.com> wrote:
> Hello
>
> I could spend few weeks looking and trying every module on cpan till
> I find something works. or I could ask on this board.
>
> is there a good module to plot my stock data 'bar chart' some module
>
> that is known to do it all kind of thing.
For *exactly* like what you're asking - no, I don't think so. Try
http://freshmeat.net/ There are several open source projects that do
*exactly* what you are asking about (and use Perl :-) ).
If you want to "roll your own", try the GD module.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"That must be wonderful! I don't understand it at all."
------------------------------
Date: Tue, 25 Nov 2003 19:49:31 GMT
From: Default@IO_Error_1011101.xyz
Subject: Re: newbie <STDIN> question
Message-Id: <fnOwb.4223$nP3.3700@nwrdny03.gnilink.net>
> > use ExtUtils::MakeMaker qw(prompt);
>
> Ugh. MakeMaker is for an entirely different purpose. Yes, it happens
> to export a routine "prompt()" that can be used here, but it carries
> a *huge* amount of luggage that is used for makefile generation and
> serves no purpose here.
>
> Look at the Term::ReadLine module for a prompter.
>
> Anno
>
Thanks for the advice.. ill check that module out right away.
------------------------------
Date: Wed, 26 Nov 2003 01:49:40 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Performance problem on SunOS 5.8
Message-Id: <20031125204939.45986500.jwillmore@remove.adelphia.net>
On 23 Nov 2003 23:06:23 -0800
kielhd@freenet.de (kielhd) wrote:
> Hi NG,
> I am running a script doing some calculations on a SunOS box. It
> takes about 11hrs to finish.
> When running the same script on WinNT, it takes only 7min!
> I was very surprised about WinNT being app. 100 times faster then
> SunOS and compared the results. The results are the same, so the
> script is working well on both machines.
> I am using perl v5.8.0 and the module Net::Netmask on both machines.
>
> Could somebody please explain this to me or - even better - give me
> a hint of how to improve the performance on SunOS.
>
> Best rgds from rainy germany
> Henning
Code would be helpful :-)
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
'I believe in getting into hot water; it keeps you clean." --
G. K. Chesterton
------------------------------
Date: 25 Nov 2003 15:42:30 -0800
From: whopper007007@yahoo.com (Sulla)
Subject: perl 5.6 multi byte
Message-Id: <fa91f49e.0311251542.66298865@posting.google.com>
Hey guys, I need to do some parsing on a file that includes Japanese
Shift JIS and Chinese GB1312 and was wondering if someone could help
me with some errors im getting. Basically, I want to open the file,
split the line by tabs, and then place the substrings in different
files. I am not entirely sure what pragmas i need to use, or really
how to open a wide character file properly (is GB1312 and Japanese
Shift JIS wide chars? Is that different from utf8?) I have been
trying to do research on multilingual support for perl 5.6, but it is
highly confusing and I am positive I am missing something. My program
is exiting early without having read the entire file (at least, it is
only getting through about 10K of a 20K line file). I've included a
code snippet and stripped out any attempts at multi-byte compatibility
I've attempted in the hopes that someone will spot what is obviously
wrong with it. Thanks so much in advance!
my %g_hMsds;
keys %g_hMsds = 60160;
open IN, "<$g_strPrimaryFile" or die "Error opening file\n"
$i = 0;
while (<IN>) {
my @aSplit = split /\t/, $_;
my @aTemp = ();
# insert into array
$aTemp[0] = $aSplit[3];
$aTemp[1] = $g_hLang{$aSplit[0]};
$aTemp[2] = $aSplit[1];
$aTemp[3] = $aSplit[4];
$aTemp[4] = "";
$aTemp[5] = $aSplit[7];
$aTemp[6] = $aSplit[8];
#attach the array
$g_hMsds{$aSplit[3]} = \@aTemp;
$i++;
if ($i >= $g_nMaxFiles) {
logResult("EXIT LOOP: ".$i." rows run");
last;
}
}
close IN;
------------------------------
Date: Tue, 25 Nov 2003 15:35:27 -0800
From: "Paul Hovnanian P.E." <Paul@Hovnanian.com>
Subject: Re: Perl Editor
Message-Id: <3FC3E73F.B3F410F5@Hovnanian.com>
AnnMarie wrote:
>
> What is the best editor for Perl CGI-Scripts?
Shouldn't this question be posted to an alt.religion group?
--
Paul Hovnanian mailto:Paul@Hovnanian.com
note to spammers: a Washington State resident
------------------------------------------------------------------
A mathematician is a machine for converting coffee into theorems.
------------------------------
Date: Tue, 25 Nov 2003 19:27:20 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Regex matching question
Message-Id: <wnSwb.181$r7.40@bignews2.bellsouth.net>
I want to be able to break a string into 2 parts. One part should be
everything before "/", the second one everything after "/" or empty if
there is no "/".
Here is some sample input data and what I would expect.
"SKULL"
"SKULL",""
"SKULL /LEFT"
"SKULL","LEFT"
"SKULL /FULL /LEFT"
"SKULL","FULL /LEFT"
I have tried with pattern matching but can't get it to work. Any help is
appreciated.
$full_desc = "SKULL";
$full_desc =~ m/(\w*)\/(\w*)/;
print "string1: $1\n";
print "string2: $2\n";
--
He is able who thinks he is able. (Buddha)
------------------------------
Date: 26 Nov 2003 00:49:57 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regex matching question
Message-Id: <slrnbs7u5l.25p.abigail@alexandra.abigail.nl>
Alexander Stremitzer (stremitz@consultant.com) wrote on MMMDCCXXXIX
September MCMXCIII in <URL:news:wnSwb.181$r7.40@bignews2.bellsouth.net>:
`` I want to be able to break a string into 2 parts. One part should be
`` everything before "/", the second one everything after "/" or empty if
`` there is no "/".
`` Here is some sample input data and what I would expect.
`` "SKULL"
`` "SKULL",""
`` "SKULL /LEFT"
`` "SKULL","LEFT"
`` "SKULL /FULL /LEFT"
`` "SKULL","FULL /LEFT"
``
`` I have tried with pattern matching but can't get it to work. Any help is
`` appreciated.
``
`` $full_desc = "SKULL";
`` $full_desc =~ m/(\w*)\/(\w*)/;
`` print "string1: $1\n";
`` print "string2: $2\n";
#!/usr/bin/perl
use strict;
use warnings;
no warnings qw /syntax/;
while (<DATA>) {
chomp;
my ($first, $second) = m {\s*/} ? ($`, $') : ($_, "");
print "First: '$first'; Second: '$second'.\n";
}
__DATA__
SKULL
SKULL /LEFT
SKULL /FULL /LEFT
First: 'SKULL'; Second: ''.
First: 'SKULL'; Second: 'LEFT'.
First: 'SKULL'; Second: 'FULL /LEFT'.
Abigail
--
BEGIN {$^H {join "" => ("a" .. "z") [8, 13, 19, 4, 6, 4, 17]} = sub
{["", "Just ", "another ", "Perl ", "Hacker"] -> [shift]};
$^H = hex join "" => reverse map {int ($_ / 2)} 0 .. 4}
print 1, 2, 3, 4, "\n";
------------------------------
Date: Wed, 26 Nov 2003 02:47:56 +0100
From: Amir Kadic <zoooz@gmx.de>
Subject: Re: Regex matching question
Message-Id: <bq0tk0$1tvfpf$1@ID-142982.news.uni-berlin.de>
Alexander Stremitzer wrote:
> I want to be able to break a string into 2 parts. One part should be
($part1, $part2) = split /\//,$string;
------------------------------
Date: Wed, 26 Nov 2003 01:22:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Regex matching question
Message-Id: <3FC4006D.3238FF23@acm.org>
Alexander Stremitzer wrote:
>
> I want to be able to break a string into 2 parts. One part should be
> everything before "/", the second one everything after "/" or empty if
> there is no "/".
> Here is some sample input data and what I would expect.
> "SKULL"
> "SKULL",""
> "SKULL /LEFT"
> "SKULL","LEFT"
> "SKULL /FULL /LEFT"
> "SKULL","FULL /LEFT"
>
> I have tried with pattern matching but can't get it to work. Any help is
> appreciated.
$ perl -le'
for ( "SKULL", "SKULL /LEFT", "SKULL /FULL /LEFT" ) {
my ( $one, $two ) = m| (\w+) \s* /? \s* (\b.*\b) |x;
print qq/ "$one", "$two" /;
}
'
"SKULL", ""
"SKULL", "LEFT"
"SKULL", "FULL /LEFT"
John
--
use Perl;
program
fulfillment
------------------------------
Date: 26 Nov 2003 01:24:56 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Regex matching question
Message-Id: <slrnbs8078.590.sholden@flexal.cs.usyd.edu.au>
On Tue, 25 Nov 2003 19:27:20 -0500,
Alexander Stremitzer <stremitz@consultant.com> wrote:
> I want to be able to break a string into 2 parts. One part should be
> everything before "/", the second one everything after "/" or empty if
> there is no "/".
> Here is some sample input data and what I would expect.
> "SKULL"
> "SKULL",""
> "SKULL /LEFT"
> "SKULL","LEFT"
> "SKULL /FULL /LEFT"
> "SKULL","FULL /LEFT"
Your data doesn't match you description. Everything before "/" includes
the space but your sample data does not..
my ($string1, $string2) = split m|\s*/|, $full_desc, 2;
>
> I have tried with pattern matching but can't get it to work. Any help is
> appreciated.
>
> $full_desc = "SKULL";
> $full_desc =~ m/(\w*)\/(\w*)/;
> print "string1: $1\n";
> print "string2: $2\n";
Clearly that regex requires a / character to appear in the string,
violating your problem description. You should also never use $1 and $2
(and the rest) variables unless you know the regex has succeeded.
And \w isn't what your description said: \w doesn't match "everything".
And doesn't match '/' which your description sample data claims should
be matched.
--
Sam Holden
------------------------------
Date: Tue, 25 Nov 2003 22:36:25 +0100
From: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: rename hash-key ?
Message-Id: <3fc3cbf7$1@e-post.inode.at>
I need to rename a hashkey and wonder how to do it best.
The following seems to work:
$hash->{newname}=$hash->{oldname};
delete $hash->{oldname};
But I wonder if this could have longterm-consequences like memleaking or
something cause its a bit complicated, especially if the value itself is a
more complicated construct and I'm paranoid of failing garbage-collection
due to circular references or whatever.
---------------------------
#! /usr/bin/perl -w
use strict;
my $h={
'one'=>{0=>'ten',1=>'eleven',2=>'twelfe?'},
'two'=>{0=>'twenty',1=>'twentyone',2=>'twentytwo'},
'tree'=>{0=>'thirty',1=>'thirtyone',2=>'thirtytwo'}
};
print $h->{tree}->{1},"\n";
$h->{three}=$h->{tree};
delete $h->{tree};
print exists $h->{tree}->{1}?'yes':'no',"\n";
print $h->{three}->{1},"\n";
--------------------------
thnx,
peter
--
peter pilsl
pilsl_usenet@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Tue, 25 Nov 2003 17:47:27 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: Re: rename hash-key ?
Message-Id: <Pine.SGI.3.96.1031125174619.36117A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Tue, 25 Nov 2003, peter pilsl wrote:
>I need to rename a hashkey and wonder how to do it best.
>
>$hash->{newname}=$hash->{oldname};
>delete $hash->{oldname};
delete() returns the key's value.
$hash{new_key} = delete $hash{old_key};
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Tue, 25 Nov 2003 11:48:42 -0800
From: I. E. <asdf@asdf.com>
Subject: Re: system() never returns, how to kill it?
Message-Id: <pcc7sv8placjq6rtni9aihinb8kcj34nmh@4ax.com>
On 25 Nov 2003 16:43:23 GMT, Abigail <abigail@abigail.nl> wrote:
I tried using this method on Win32 but the system commnd still
executes as a background process and consumes resources. Is there any
way to kill it on Win32?
>#!/usr/bin/perl
>
>use strict;
>use warnings;
>
>print scalar localtime, ": Start\n";
>
>eval {
> local $SIG {ALRM} = sub {die "Timeout!"};
> alarm (5);
> system "sleep 1000000"; # Some long running command.
>};
>
>die $@ if $@ && $@ !~ /Timeout/;
>
>print scalar localtime,
> ": External program timed out.\n" if $@ && $@ =~ /Timeout/;
>
>print scalar localtime, ": End\n";
>
>__END__
>Tue Nov 25 17:41:59 2003: Start
>Tue Nov 25 17:42:04 2003: External program timed out.
>Tue Nov 25 17:42:04 2003: End
>
>
>
>Abigail
................................................................
Posted via TITANnews - Uncensored Newsgroups Access
>>>> at http://www.TitanNews.com <<<<
-=Every Newsgroup - Anonymous, UNCENSORED, BROADBAND Downloads=-
------------------------------
Date: 25 Nov 2003 13:29:16 -0800
From: jguad98@hotmail.com (John)
Subject: Re: trying to understand fork and wait
Message-Id: <a964da31.0311251329.ca062f5@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbs5di1.2eb.tadmc@magna.augustmail.com>...
> John <jguad98@hotmail.com> wrote:
>
> > I ran it and it failed ... specifically the fork is
>
> So did you then read the docs for fork() ?
>
Yes, and I saw nothing new from when I read the docs before. It's
that whole issue with the doco being farking vague and incomplete
causing confusion which I mentioned (or at least implied) in my
previous postings in this thread.
>
> > failing with this message:
> >
> > Uncaught exception from user code:
> > 17234: cannot fork: No such file or directory at
> > ./testlogreader.pl line 77.
> > Use of uninitialized value at ./testlogreader.pl line 25 (#1)
> >
> > (W) An undefined value was used as if it were already defined. It
> > was
> > interpreted as a "" or a 0, but maybe it was a mistake. To
> > suppress this
> > warning assign an initial value to your variables.
> >
> >
> > I put "use:diagnostics" in the script
>
>
> I doubt that...
>
mia culpa ... my statement above is technically inaccurate ... in
fact, I put "use diagnostics" in my script, no colon.
<SNIP>
>
> If the fork did _not_ fail, then $! will contain a left-over
> message and cannot be relied upon.
>
> > 77 my $kidpid = fork() or die "$$: cannot fork: $!";
>
> perldoc -f fork
>
> Says that fork() will return one of three things:
>
> PID in the parent process
> zero in the child process
> undef if the fork() fails
>
> Your die() will execute in either of those last two cases.
>
> defined(my $kidpid = fork()) or die "$$: cannot fork: $!";
>
> > There's nothing in the fork instruction that references any file or
> > directory, so why does it look like it's trying to find a file or dir?
>
> It isn't, the message is stale. The real problem is the logic of
> your "or die".
Thank you, I just slapped on the 'or die' to provide for <IRONY>
better debugging </IRONY> ... so my 'or die' statement was not set up
correctly, causing more problems for me that I would have had without
it.
I did not know that "$!" could have a "stale" message ... if I had
realized that, I might have figured out that the problem was the "or
die" and not the "fork" ... I do not have every last nuance of Perl
burned into my cerebral cortex ... I'm learning as I'm doing.
regards,
John
------------------------------
Date: Tue, 25 Nov 2003 23:07:05 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: trying to understand fork and wait
Message-Id: <bq0nap$rrn$1@wisteria.csv.warwick.ac.uk>
jguad98@hotmail.com (John) wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message
> news:<slrnbs5di1.2eb.tadmc@magna.augustmail.com>...
> > John <jguad98@hotmail.com> wrote:
> >
> > > I ran it and it failed ... specifically the fork is
> >
> > So did you then read the docs for fork() ?
>
> Yes, and I saw nothing new from when I read the docs before. It's
> that whole issue with the doco being farking vague and incomplete
> causing confusion which I mentioned (or at least implied) in my
> previous postings in this thread.
The documentation for fork states quite explicitly in the first
paragraph what fork returns. I take it you realise that 0 is false?
> mia culpa ...
ITYM 'mea' :)
> > If the fork did _not_ fail, then $! will contain a left-over
> > message and cannot be relied upon.
<snip>
> > It isn't, the message is stale. The real problem is the logic of
> > your "or die".
>
> I did not know that "$!" could have a "stale" message ...
Again, it says so quite clearly in perlvar under $!.
| This means that the value of $! is meaningful only *immediately*
| after a *failure*: ... In the above *meaningless* stands for
| anything: zero, non-zero, "undef". A successful system or library
| call does *not* set the variable to zero.
If you have got yourself accustomed to simply slapping 'or die' after
each syscall (not a bad habit in general) you should be aware that
system() will not return what you expect either.
Ben
--
EAT
KIDS (...er, whoops...)
FOR ben@morrow.me.uk
99p
------------------------------
Date: Wed, 26 Nov 2003 01:29:17 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: trying to understand fork and wait
Message-Id: <20031125202917.7c886c2d.jwillmore@remove.adelphia.net>
On 25 Nov 2003 13:29:16 -0800
jguad98@hotmail.com (John) wrote:
<snip>
> I did not know that "$!" could have a "stale" message ... if I had
> realized that, I might have figured out that the problem was the "or
> die" and not the "fork" ... I do not have every last nuance of Perl
> burned into my cerebral cortex ... I'm learning as I'm doing.
*How* are you learning by doing? *Most*, if not all, books,
tutorials, etc. that are written by *good* (not expert or "guru")
programmers *always* use '... or die "$!\n"' after a system call,
opening a file or anything done in Perl that has the potential of
returning a system error. Shame on those who don't.
No one expects to *know* all of Perl. I'm pretty certain that even
those who are deeply involved in the development of Perl don't know
*everything* about Perl :-)
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Just because you're paranoid doesn't mean they AREN'T after you.
------------------------------
Date: Tue, 25 Nov 2003 12:27:51 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: undif as if it is 0
Message-Id: <etohe0sz1s8.fsf@fc.hp.com>
Edo <eddhig22@yahool.com> writes:
> and how to fix that?
http://lists.boost.org/MailArchives/boost/msg35365.php
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Tue, 25 Nov 2003 15:19:15 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: undif as if it is 0
Message-Id: <3FC3B943.4070800@gwu.edu>
Edo wrote:
> Eric J. Roode wrote:
>
>>
>> Yes. Tabs. Tabs don't work well over Usenet. (Imho, they don't work
>> well *anywhere*).
>>
>
> and how to fix that?
>
Don't use them. Give serious thought to a global replacing of any
tabs that may currently be in your source files.
Chris Mattern
------------------------------
Date: Wed, 26 Nov 2003 09:18:21 +1100
From: Edo <eddhig22@yahool.com>
Subject: Re: undif as if it is 0
Message-Id: <3FC3D52D.5070903@yahool.com>
I got it, I hope this is correct in all aspect.
thanks for helping
sub scan (\%\%\%) {
my ($dbits, $sbits, $set) = @_;
my @kd = keys %$dbits; my @ks = keys %$sbits;
my @vs = values %$sbits;
for( 0 .. (@kd - @ks) ) {
my @kdslic = @kd[$_ .. $_+@ks-1 ];
my @vd = @$dbits{@kdslic};
my $tmp = check( \@vd, \@vs );
my @k = keys %$set;
my $max = (sort {$b <=> $a} @k)[0] || 0;
if (( $tmp > $max )||($tmp = 1)) {
tie my (%slic), 'Tie::IxHash';
foreach my $ky ( @kdslic ){
$slic{$ky} = $$dbits{$ky};
}
push @{$set->{$tmp}},\%slic;
if ($#k > 3) {
delete $$set{$k[$#k]};
}
}
}
}
------------------------------
Date: Tue, 25 Nov 2003 18:05:52 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: undif as if it is 0
Message-Id: <3FC3E050.9030306@gwu.edu>
Edo wrote:
> Chris Mattern wrote:
>
>> Edo wrote:
>>
>>> Eric J. Roode wrote:
>>>
>>>>
>>>> Yes. Tabs. Tabs don't work well over Usenet. (Imho, they don't
>>>> work well *anywhere*).
>>>>
>>>
>>> and how to fix that?
>>>
>> Don't use them. Give serious thought to a global replacing of any
>> tabs that may currently be in your source files.
>>
>> Chris Mattern
>>
>
> sorry, can you be more clear, you mean instead of hitting Tab to indent
> my line of code I should do (??) what?
>
Press the space bar. Twice.
Chris Mattern
------------------------------
Date: Tue, 25 Nov 2003 17:37:09 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: undif as if it is 0
Message-Id: <Xns943EBD7C6EC93sdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Edo <eddhig22@yahool.com> wrote in news:3FC3D2DF.7000302@yahool.com:
> sorry, can you be more clear, you mean instead of hitting Tab to indent
> my line of code I should do (??) what?
Use the space bar n times. Or: Most modern editors will insert an
appropriate number of spaces when you hit the tab key. Learn how to use
this feature in your editor. Or: after each edit session, do a global
replace on tabs.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP8Pnv2PeouIeTNHoEQLIWwCgnSz1FNuboFdBVtZh07b7G6txSHgAn34f
vy6wpMhQP925zrebQAOtH1v0
=A+AS
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 25 Nov 2003 14:41:42 -0500
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Unexpected tell() result
Message-Id: <dwilga-MUNGE-600801.14414225112003@nap.mtholyoke.edu>
I'm seeing odd results when tell() is performed right after open with
append:
#!/usr/bin/perl -w
use strict;
open( FOO, ">foo" ) || die;
print FOO "test";
close FOO;
open( FOO, ">>foo" ) || die;
print "-s: ".(-s "foo")."\n";
print "tell: ".(tell FOO)."\n";
close FOO;
unlink( "foo" ) || die;
Under RedHat 7.1 (perl 5.8.0, glibc-2.2.4-32) I get:
-s: 4
tell: 4
which is what I expect. A Tru64 machine also returns these values.
However, under RedHat 8.0 (perl 5.8.0, glibc-2.3.2-4.80.8) I get:
-s: 4
tell: 0
Perl on the RH 8 system is not the RedHat rpm; it is compiled from
scratch. I get the same (bad) results with RH 9 and glibc-2.3.2-27.9.7.
Since the same version of Perl gives different results, I suspect a
glibc bug. Can anyone confirm this?
Is there a compile-time option that would avoid this?
--
Dan Wilga dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **
------------------------------
Date: Tue, 25 Nov 2003 20:22:47 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Unexpected tell() result
Message-Id: <bq0dmn$lb8$1@wisteria.csv.warwick.ac.uk>
Dan Wilga <dwilga-MUNGE@mtholyoke.edu> wrote:
> I'm seeing odd results when tell() is performed right after open with
> append:
>
<snip>
> Under RedHat 7.1 (perl 5.8.0, glibc-2.2.4-32) I get:
>
> -s: 4
> tell: 4
>
> which is what I expect. A Tru64 machine also returns these values.
>
> However, under RedHat 8.0 (perl 5.8.0, glibc-2.3.2-4.80.8) I get:
>
> -s: 4
> tell: 0
>
<snip>
> Since the same version of Perl gives different results, I suspect a
> glibc bug. Can anyone confirm this?
I get the same results on Gentoo, perl 5.8.0, glibc 2.3.2, gcc 3.2.3,
linux 2.4.19.
A further demonstration that this behaviour is actually wrong:
% perl -wle'open my $O, ">foo" or die $!; print $O "foo"; close $O; \
open $O, ">>foo" or die $!; print $O "bar"; print tell $O'
4
%
despite the fact that 'bar' ends at position 8 in the file.
Ben
--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: 25 Nov 2003 15:43:48 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Unexpected tell() result
Message-Id: <3fc3e934@news.victoria.tc.ca>
Dan Wilga (dwilga-MUNGE@mtholyoke.edu) wrote:
: I'm seeing odd results when tell() is performed right after open with
: append:
: #!/usr/bin/perl -w
: use strict;
: open( FOO, ">foo" ) || die;
: print FOO "test";
: close FOO;
: open( FOO, ">>foo" ) || die;
: print "-s: ".(-s "foo")."\n";
: print "tell: ".(tell FOO)."\n";
: close FOO;
: unlink( "foo" ) || die;
: Under RedHat 7.1 (perl 5.8.0, glibc-2.2.4-32) I get:
: -s: 4
: tell: 4
: which is what I expect. A Tru64 machine also returns these values.
: However, under RedHat 8.0 (perl 5.8.0, glibc-2.3.2-4.80.8) I get:
: -s: 4
: tell: 0
You've opend the file in append mode, so any write is supposed to go to
the end of the file, whereever that happens to be. However, the size of
the file could be changing due to another process, so the value of tell
that you read at one moment doesn't really have any relation to where the
data gets written.
I think the only question is whether a print to the handle writes the data
to the correct location in the file.
------------------------------
Date: 25 Nov 2003 19:06:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: unpack query
Message-Id: <bq097c$62h$1@mamenchi.zrz.TU-Berlin.DE>
Jack Penarth <jackpenarth@aol.com> wrote in comp.lang.perl.misc:
> jackpenarth@aol.com (Jack Penarth) wrote in message
> news:<f27d1c90.0311241113.55659dbc@posting.google.com>...
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<bpt20n$rnv$1@mamenchi.zrz.TU-Berlin.DE>...
[big snip]
> Just an update from me.
>
> As I said, I am inexperienced with perl and it would appear that I am
> not running under strict.
>
> However, with your help I was able to modify my code (I noticed the my
> %seen typo) and, because I realised that the identifier actually
> occupied two field, I was able to incorporate that as well as follows:
>
> > my $seen;
> > while ( <FILE> ) {
> > $field1, $field2, $field3, $field4, $field5, $field6, $field7,
> > $field7, $field8, $field9, $field10, $field11, $field12, $field13,
> > $field14, $field15, $field16) = unpack($format1, $_);
> > next if $seen{ $field3, $field4};
^^^^^^^^^^^^^^^^
> > write(OUT_PUT);
> > $seen{ $field3, field4} = 1;
^^^^^^^^^^^^^^^
There's a "$" missing before "field4". This is either a bug in your
program, or you have been re-typing the code. Use copy/paste to
transfer code to a news message.
> > }
>
> It now works perfectly.
Uh, oh. The highlighted syntax isn't standard Perl, it's a leftover from
Perl 4 and shouldn't be used without understanding its limitations. I bet
you just guessed the syntax might work, and it did. (Curses in the DWIMmer's
general direction)
What you are using is known as multidimensional hash emulation. It's
described in _Programming Perl_ Ch. 2, Section _Hashes_. It's also
in the online documentation, but offhand I don't know where.
A better way to write it is
$seen{ $field3}->{ $field4}
which is a true (well, "truer", to quote the Camel) two-dimensional
hash.
Anno
------------------------------
Date: Tue, 25 Nov 2003 20:07:47 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: unpack query
Message-Id: <bq0cqj$k37$1@wisteria.csv.warwick.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> What you are using is known as multidimensional hash emulation. It's
> described in _Programming Perl_ Ch. 2, Section _Hashes_. It's also
> in the online documentation, but offhand I don't know where.
perlvar, under $;
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
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.
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 5858
***************************************