[21886] in Perl-Users-Digest
Perl-Users Digest, Issue: 4090 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 9 14:06:49 2002
Date: Sat, 9 Nov 2002 11:05:08 -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 Sat, 9 Nov 2002 Volume: 10 Number: 4090
Today's topics:
Re: "each" loop on hash inconsistent? <rja@euronet.nl>
Re: "each" loop on hash inconsistent? <rick.delaney@rogers.com>
Re: "each" loop on hash inconsistent? <rja@euronet.nl>
Re: CPAN for rootless (l)users. <ocscwar@h-after-ocsc.mit.edu>
Re: How to kill a system or process open call on timeo (Seth Brundle)
Problem with mailing list - email sent out without carr <dave.steiner@gmx.net>
Re: Safest way to convert $d.cc to $DCC ? <flavell@mail.cern.ch>
Simple, almost stupid question! <100.17706@germanynet.de>
Re: Simple, almost stupid question! <fxn@hashref.com>
Re: Simple, almost stupid question! <fxn@hashref.com>
Re: Simple, almost stupid question! <fxn@hashref.com>
XQL Dates <emiperez@jaiak.net>
zeile aus der datei ausschneiden <euv01657@student.euv-frankfurt-o.de>
Re: zeile aus der datei ausschneiden <jurgenex@hotmail.com>
Re: zeile aus der datei ausschneiden <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 09 Nov 2002 17:37:46 +0100
From: Rick Jansen <rja@euronet.nl>
Subject: Re: "each" loop on hash inconsistent?
Message-Id: <3DCD39DA.2030706@euronet.nl>
Bob Walton wrote:
> Rick Jansen wrote:
>
>> Dear all,
>>
>> I'm experiencing strange behavior with a while-each loop
>> reading a hash: sometimes NOT the entire hash is scanned.
>>
>> The program in question is a perl daemon, copying a hash
>> from a GDBM file into a regular hash variable in memory,
>> and then returning records from this hash based on requests
>> it handles. Something like this:
>>
>> Initialize:
>>
>> tie %Hash,"GDBM_File", "$DB_FileName", &GDBM_READER(), 0644;
>> %ScanHash = %Hash;
>> untie %Hash;
>>
>> Running in daemon mode, repeatedly the following happens:
>>
>> $Count = 0;
>> while ( ($index,$value) = each %ScanHash ) {
>> $Count++;
>> ;;
>> }
>>
>> The hash is about 1500 records and does not change. I log the
>> scanning process, and 99.9% of cases indeed those 1500 records
>> are scanned, which is correct. But, in 0.1% of cases scanning
>> stops at, say 998 records, or 259. A seemingly random number.
>>
>> Since I noticed this, I simply built-in a retry: if $Count is
>> not 1500 I simply repeat the while-each loop, and then $Count
>> indeed reaches 1500. So, it would seem the hash itself is in
>> order, why does the loop end before the full 1500 entries are
>> processed..?
>>
>> - This happens on two different machines, one Solaris 2.8, the other
>> Solaris 2.5, both perl 5.6.1
>> - The daemon is non-forking, it handles consecutive tcp requests.
>> - The damon is not running long before the 'error' happens.
>> - There are no memory problems on the machines, nor too many processes,
>> nor does the daemon process grow (much) in size over time.
>>
>> Any pointers would be appreciated!
>>
>
>
> Hmmmm...a daemon process? So I assume other processes are also
> accessing this gdbm file, perhaps for write? If so, you need a locking
> scheme:
NO! The while-each loop does NOT scan the GDBM, but a memory COPY!
(I know about locking DBM's.) I only mention it in my text just in case
copying a hash from a tied hash would be different from creating a hash
from scratch. I'm not aware of a difference, but the fact that a bit
of code is unpredictable is unsettling enough already.
Rick Jansen
__
rja@euronet.nl http://www.euronet.nl/~rja
____________________________________________
S&H's a module and s&h's looking good
------------------------------
Date: Sat, 09 Nov 2002 16:58:00 GMT
From: Rick Delaney <rick.delaney@rogers.com>
Subject: Re: "each" loop on hash inconsistent?
Message-Id: <m3smya1y08.fsf@cs839290-a.mtth.phub.net.cable.rogers.com>
Rick Jansen <rja@euronet.nl> writes:
> Dear all,
>
> I'm experiencing strange behavior with a while-each loop
> reading a hash: sometimes NOT the entire hash is scanned.
[...]
> Running in daemon mode, repeatedly the following happens:
>
> $Count = 0;
> while ( ($index,$value) = each %ScanHash ) {
> $Count++;
> ;;
> }
Are there any breaks out of this loop? Or any other
instances of 'each %ScanHash' that aren't given a chance
of running through all elements?
If so, then each will pick up where it left off when you
try again. Use 'scalar keys %ScanHash' to reset the
iterator if this is the case.
--
Rick Delaney
rick.delaney@rogers.com
------------------------------
Date: Sat, 09 Nov 2002 18:13:38 +0100
From: Rick Jansen <rja@euronet.nl>
Subject: Re: "each" loop on hash inconsistent?
Message-Id: <3DCD4242.2070908@euronet.nl>
Rick Delaney wrote:
> Rick Jansen <rja@euronet.nl> writes:
>
>
>>Dear all,
>>
>>I'm experiencing strange behavior with a while-each loop
>>reading a hash: sometimes NOT the entire hash is scanned.
>
>
> [...]
>
>
>>Running in daemon mode, repeatedly the following happens:
>>
>> $Count = 0;
>> while ( ($index,$value) = each %ScanHash ) {
>> $Count++;
>> ;;
>> }
>
>
> Are there any breaks out of this loop? Or any other
> instances of 'each %ScanHash' that aren't given a chance
> of running through all elements?
>
> If so, then each will pick up where it left off when you
> try again. Use 'scalar keys %ScanHash' to reset the
> iterator if this is the case.
Ah, this might very well be IT!
Yes, there ARE exits from the each loop, in case too many results
are found, and it's a global var in a running daemon, so the each
iterator remains...
How would 'scalar keys %ScanHash' perform for very big hashes, like
a DBM tied hash...? Is there another way to reset the each iterator?
Thanks!
Rick Jansen
__
rja@euronet.nl http://www.euronet.nl/~rja
____________________________________________
S&H's a module and s&h's looking good
------------------------------
Date: 09 Nov 2002 11:15:24 -0500
From: Omri Schwarz <ocscwar@h-after-ocsc.mit.edu>
Subject: Re: CPAN for rootless (l)users.
Message-Id: <octlm4290tf.fsf@magic-pi-ball.mit.edu>
"Randy Kobes" <randy@theoryx5.uwinnipeg.ca> writes:
> "Omri Schwarz" <ocscwar@h-after-ocsc.mit.edu>
> wrote in message news:oct4rara5lq.fsf@no-knife.mit.edu...
> > Pierre Asselin <pa@panix.com> writes:
> >
> > > In <octisz8hqb0.fsf@no-knife.mit.edu> Omri Schwarz
> <ocscwar@h-after-ocsc.mit.edu> writes:
> > >
> > > >How do I tell CPAN that the installation
> > > >prefix I need for my Perl module makefiles
> > > >is not anywhere in /usr land but is in fact
> > > >~/perllib?
> > >
> > > IIRC you can specify that when you first run "perl -MCPAN -e shell".
> >
> > No go. That sets my build and cache directories,
> > but never asks about the install prefix.
> >
> > I presume I should just be able to add something
> > to ~/.cpan/CPAN/MyConfig.pm. I just don't know what.
>
> You'd want to add the appropriate PREFIX=... to
> CPAN.pm's makepl_arg setting.
That worked. Thanks!
>
> best regards,
> randy kobes
>
>
>
--
Omri Schwarz --- ocscwar@mit.edu ('h' before war)
Timeless wisdom of biomedical engineering: "Noise is principally
due to the presence of the patient." -- R.F. Farr
------------------------------
Date: 9 Nov 2002 09:28:22 -0800
From: brundlefly76@hotmail.com (Seth Brundle)
Subject: Re: How to kill a system or process open call on timeout
Message-Id: <53e2ec95.0211090928.2a421ae3@posting.google.com>
"J rgen Exner" <jurgenex@hotmail.com> wrote in message news:<HA1z9.3647$XH4.1538@nwrddc02.gnilink.net>...
> Seth Brundle wrote:
> > I would like to be able to kill a system call or piped open process if
> > it runs over, say a minute.
>
> Please see "perldoc -q timeout": How do I timeout a slow event?
>
> jue
thanks not only for this info but for turning me on to perdoc's '-q'
switch after all these years ;P
------------------------------
Date: Sat, 09 Nov 2002 18:01:19 +0100
From: Dave Steiner <dave.steiner@gmx.net>
Subject: Problem with mailing list - email sent out without carriage returns - sendmail problem?
Message-Id: <pveqsu8f6j0ufn69gcgsp5tif295f2h279@4ax.com>
Hi everyone,
I have a problem implementing a mailing list.
I am on a Unix Server installing Mailmerge - a freeware mailing tool.
The problem is that it sends out the email without any formatting
whatsoever, more precisely: it leaves out all carriage returns and
wouldn't show links as links (blue, underlined)
This already happened with a similar perl script, but I am unsure what
I am doing wrong.
Things I have tried so far:
- adjusting the charset to iso-8859-1.
- installed different script
- checked email with different clients.
Could this be a problem with sendmail? It's used with -t.
Any help will be greatly appreciated, since I am completely clueless
here and not very experienced.
Thanks,
Dave.
Problem with mailing list - email sent out without carriage returns -
sendmail problem?
------------------------------
Date: Sat, 9 Nov 2002 18:02:55 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Safest way to convert $d.cc to $DCC ?
Message-Id: <Pine.LNX.4.40.0211091754460.1657-100000@lxplus072.cern.ch>
On Nov 9, Kirk Is inscribed on the eternal scroll:
> Tad McClellan <tadmc@augustmail.com> wrote:
>
> >> If I have a dollar amount represented as a floating point number,
> > The safest way is to not use floating point numbers.
>
> Yeah, I know, but the incoming source has a decimal point.
That doesn't make it into a floating point number. That seems to be a
common misapprehension, but a fixed-point number can be treated as an
integer as long as you take care of the position of the point
separately. Which is in effect what is being recommended here:
> > Use cents (integers) instead of dollars.
>
> Yup.
See?
> It's data I'm getting from an Oracle db, somefield that's
> like NUMBER(14,2) or some such. Oracle keeps that stuff safe,
> right? Something closer to string handling (is packed decimal
> the term?) than floating point.
Why should it matter how the database actually _stores_ it, as long as
it maintains precision? - all that you need to know is what your
programming interface to the database API requires.
(Back in IBM mainframe days, the term "packed decimal" referred to a
decimal number having an odd number of digits, which was packed like
dd dd dd ds , two digits per byte with "s" as the sign indicator.
But you probably don't need to know that ;-)
------------------------------
Date: Sat, 09 Nov 2002 19:01:07 +0100
From: Rick Denoire <100.17706@germanynet.de>
Subject: Simple, almost stupid question!
Message-Id: <g6jqsuc60otkfqoajk3gs2g2v81jksv2qs@4ax.com>
Hello
Take a look to this line:
perl -p -i -e 's/$old/$new/g' target_file
meaning to replace $old by $new in the target file.
But if using a large number of substitute commands, the line would get
too long: "-e command1 -e command2 -e command3 ...."
I do have more than 200 such commands to execute on a number of files
as target. Let's assume that I have a file sub_list with two columns
containing $old in the first and $new in the second column:
this that
white black
high low
etc
Since perl should be able to read the commands from a file, I am
looking for the correct option to do this:
echo "target1 target2 ...." | xargs perl -p -i <option> sub_list
So I would apply all commands contained in sub_list to all target
files. Would that be possible? I just don't know what the <option>
should be (I warned, this is a stupid question). Of course, I could
create sub_list containing the commands needed for perl, not only the
substitution strings, so the file would look like this:
s/this/that/g
s/white/black/g
s/high/low/g
etc.
(not sure if I should enclose every line, or the whole block of lines
in apostrophes, or perhaps without any at all). Btw, if $old is not
found in a file, that should not break the perl call.
Sorry for this simple question, I am a casual perl user and even after
I went through a whole book I could not find the answert to this
question.
(using Solaris 2.7 and perl 5.0)
ANY hint would be highly appreciated!
Bye
Rick
------------------------------
Date: Sat, 9 Nov 2002 18:30:11 +0000 (UTC)
From: "F. Xavier Noria" <fxn@hashref.com>
Subject: Re: Simple, almost stupid question!
Message-Id: <aqjk7j$ant$1@news.ya.com>
In article <g6jqsuc60otkfqoajk3gs2g2v81jksv2qs@4ax.com>, Rick Denoire wrote:
> Take a look to this line:
> perl -p -i -e 's/$old/$new/g' target_file
>
> meaning to replace $old by $new in the target file.
> But if using a large number of substitute commands, the line would get
> too long: "-e command1 -e command2 -e command3 ...."
>
> I do have more than 200 such commands to execute on a number of files
> as target. Let's assume that I have a file sub_list with two columns
> containing $old in the first and $new in the second column:
>
> this that
> white black
> high low
> etc
>
> Since perl should be able to read the commands from a file, I am
> looking for the correct option to do this:
>
> echo "target1 target2 ...." | xargs perl -p -i <option> sub_list
Well, if you want a one-liner this would do the trick for one file:
cat foo.pairs | while read old new; do
perl -pi -e "s/$old/$new/g" foo.txt; done
where foo.pairs contains pairs "old new" per line. Note the double quotes to
have the shell interpolate $old and $new before perl gets called.
Another while+read or cat+xargs piece could deal with a file containing the
list of files to work on.
As you suggested it is possible to store s/// commands in a file instead of
pairs of words and then eval them, but as you see is unnecessary.
-- fxn
------------------------------
Date: Sat, 9 Nov 2002 18:36:18 +0000 (UTC)
From: "F. Xavier Noria" <fxn@hashref.com>
Subject: Re: Simple, almost stupid question!
Message-Id: <aqjkj2$ant$2@news.ya.com>
In article <aqjk7j$ant$1@news.ya.com>, F. Xavier Noria wrote:
> cat foo.pairs | while read old new; do
> perl -pi -e "s/$old/$new/g" foo.txt; done
Sorry, I forgot to escape the variables for perl there:
cat foo.pairs | while read old new; do
perl -pi -e "s/\\Q$old\\E/quotemeta($new)/ge" foo.txt; done
-- fxn
------------------------------
Date: Sat, 9 Nov 2002 19:02:55 +0000 (UTC)
From: "F. Xavier Noria" <fxn@hashref.com>
Subject: Re: Simple, almost stupid question!
Message-Id: <aqjm4v$ca1$1@news.ya.com>
In article <aqjkj2$ant$2@news.ya.com>, F. Xavier Noria wrote:
> In article <aqjk7j$ant$1@news.ya.com>, F. Xavier Noria wrote:
>
>> cat foo.pairs | while read old new; do
>> perl -pi -e "s/$old/$new/g" foo.txt; done
>
> Sorry, I forgot to escape the variables for perl there:
>
> cat foo.pairs | while read old new; do
> perl -pi -e "s/\\Q$old\\E/quotemeta($new)/ge" foo.txt; done
Nah, that is broken as well, words with parens, sharps, etc. would give code
with invalid syntax. I think I'd write a script for that.
-- fxn
------------------------------
Date: Sat, 09 Nov 2002 18:00:31 +0100
From: Emilio Perez <emiperez@jaiak.net>
Subject: XQL Dates
Message-Id: <3DCD3F2F.4090509@jaiak.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
I have a XML document like this:
<?xml version='1.0' encoding='ISO-8859-1' standalone='no'?>
<fiestas>
~ <fiesta cod='1405' fechini='06/01/02' fechfin='06/01/02' nom='Erregeen
eguna, ' actos='no' sitio_cod='01307D' />
~ <fiesta cod='1406' fechini='06/01/02' fechfin='06/01/02' nom='Erregeen
eguna, (Urrengo igandean jaia)' actos='no' sitio_cod='20210' />
~ <fiesta cod='1407' fechini='06/01/02' fechfin='06/01/02' nom='Erregeen
eguna, Escenificación de los reyes' actos='no' sitio_cod='31400' />
~ <fiesta cod='1408' fechini='08/01/02' fechfin='08/01/02' nom='Julen
Deuna, ' actos='no' sitio_cod='48550' />
...
</fiestas>
I need to make a XQL query to obtain all fiestas in a given month
(@fechini's month <= $month $and$ @fechfin's month >= $month )
How can I obtain the month from the refered attributes?
I probed with this query :
$consulta="/fiestas/fiesta[date(\@fechini) < date('01/$mon_num/2002')]";
but it doesnt work.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE9zT8uK5dSzDDMru0RAtEGAJ9P0hOsCovB4Na2PnO2ldIWfqXbzgCfSD1k
3HFODv+bRzJ+ar4WAwEG3yk=
=vliA
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 9 Nov 2002 17:45:21 +0100
From: magda muskala <euv01657@student.euv-frankfurt-o.de>
Subject: zeile aus der datei ausschneiden
Message-Id: <Pine.GSO.4.43.0211091738150.27139-100000@viadukt.euv-frankfurt-o.de>
hallo, konnte mir jemand helfen dieser teil von code so korriegrieren,
dass es alles ausser einer zeile(die mit eingegebener $benutzer variable
begint)
aus der datei bio.txt zu tmp.txt kopiert wird.
open (I, "<bio.txt");
open (O, ">tmp.txt");
while (<I>)
{
if(/^$benutzer/)
{
$_=$zeile;
$_ =~ s/$zeile//;
}
print O "$_";
close(I); close(O);
}
danke im voraus
gruesse
--
magda
http://viadukt.euv-frankfurt-o.de/~euv01657
magdalena.muskala@euv-frankfurt-o.de
------------------------------
Date: Sat, 09 Nov 2002 16:54:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: zeile aus der datei ausschneiden
Message-Id: <05bz9.8585$Dl.5560@nwrddc01.gnilink.net>
magda muskala wrote:
> hallo, konnte mir jemand helfen dieser teil von code so korriegrieren,
> dass es alles ausser einer zeile(die mit eingegebener $benutzer
> variable begint)
What is the problem, i.e. which unwanted behaviour do you observe with your
current code?
> aus der datei bio.txt zu tmp.txt kopiert wird.
>
> open (I, "<bio.txt");
> open (O, ">tmp.txt");
> while (<I>)
> {
> if(/^$benutzer/)
> {
>
>
> $_=$zeile;
> $_ =~ s/$zeile//;
> }
> print O "$_";
>
> close(I); close(O);
I would just replace the whole body of the loop with a simple
print O unless (/^$benutzer);
jue
>
> }
>
> danke im voraus
> gruesse
------------------------------
Date: Sat, 09 Nov 2002 17:16:46 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: zeile aus der datei ausschneiden
Message-Id: <2qbz9.8275$XH4.5876@nwrddc02.gnilink.net>
Jürgen Exner wrote:
[Sorry for following up on my posting, but just found several additional
problems in your code]
> magda muskala wrote:
>> hallo, konnte mir jemand helfen dieser teil von code so
>> korriegrieren, dass es alles ausser einer zeile(die mit eingegebener
>> $benutzer variable begint)
>
> What is the problem, i.e. which unwanted behaviour do you observe
> with your current code?
>
>> aus der datei bio.txt zu tmp.txt kopiert wird.
>>
You should always enable strictures and warnings:
use strict;
use warnings;
>> open (I, "<bio.txt");
You should always check the success of an open:
open (I, "<bio.txt") or die "Cannot open bio.txt because $!\n";
>> open (O, ">tmp.txt");
You should always check the success of an open:
open (I, ">tmp.txt") or die "Cannot open tmp.txt because $!\n";
>> while (<I>)
>> {
>> if(/^$benutzer/)
>> {
>>
>>
>> $_=$zeile;
Why are you overwriting the line you just read with $zeile? Where is $zeile
coming from?
If you would have enabled warnings then Perl would have told you that this
is no good:
Use of uninitialized value in .....
>> $_ =~ s/$zeile//;
[$_ is the default for the s command, not need to bind s to $_
explicitely. ]
And now you are substituting the content of $_ (which happens to be
identical to $zeile because of the previous assignment) with nothing.
Those two lines above can be simplified to
$_ = '';
>> }
>> print O "$_";
>>
>> close(I); close(O);
>>
>> }
You are closing the file handles inside of the loop, i.e. they will be
closed after processing the first input line only.
If you would have enabled warnings then perl would have told you that this
is no good:
readline() on closed filehandle main::I at C:\tmp\t.pl line 4.
Oh, and btw: the standard language in this NG is English. Your chances of
getting a reply are far better if you ask in English.
If you want to discuss in German then you may want check out the German Perl
NG: de.comp.lang.perl
jue
------------------------------
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 4090
***************************************