[21885] in Perl-Users-Digest
Perl-Users Digest, Issue: 4089 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 9 11:06:22 2002
Date: Sat, 9 Nov 2002 08:05:07 -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: 4089
Today's topics:
"each" loop on hash inconsistent? <rja@euronet.nl>
Re: "each" loop on hash inconsistent? <bwalton@rochester.rr.com>
[ANNOUNCE] Tk::MinMaxScale 0.05 released <jeanpierre.vidal@free.fr>
Re: A vision for Parrot <usenet@jasoegaard.dk>
Re: Pause in perl ??? <mail@eircom.net>
Re: Safest way to convert $d.cc to $DCC ? <kirkspam@alienbill.com>
Re: Substrings <bwalton@rochester.rr.com>
Re: wish fast method of counting of characters <rja@euronet.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 09 Nov 2002 15:39:51 +0100
From: Rick Jansen <rja@euronet.nl>
Subject: "each" loop on hash inconsistent?
Message-Id: <3DCD1E37.8000909@euronet.nl>
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!
Rick Jansen
__
rja@euronet.nl http://www.euronet.nl/~rja
------------------------------
Date: Sat, 09 Nov 2002 15:58:13 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: "each" loop on hash inconsistent?
Message-Id: <3DCD3075.9000303@rochester.rr.com>
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:
perldoc -q lock
Without a locking scheme, you are very fortunate you haven't corrupted
your database already. Or maybe you have :-). The locking scheme is a
cooperative lock, which prevents other processes from reading or
modifying the file during the times the file is being modified by some
process, and also from modifying the file while it is being read by one
or more other processes.
Note that file locking is not a trivial matter to get right. Be sure to
read *all* your OS's docs and Perl's docs on file locking, and to follow
all the guidelines to the letter. It is difficult to verify that a
given scheme is truly bulletproof. Some OS's may not implement proper
locks for networked files. A separate lock file with no content used
exclusivley for the purposes of establishing a lock on your data files
or other shared resources is the easiest and most bulletproof way of
doing locking.
> Rick Jansen
...
--
Bob Walton
------------------------------
Date: Sat, 9 Nov 2002 00:00:53 +0800
From: "Jean-Pierre Vidal" <jeanpierre.vidal@free.fr>
Subject: [ANNOUNCE] Tk::MinMaxScale 0.05 released
Message-Id: <3dccfbaf$1_2@news.teranews.com>
Tk::MinMaxScale is a composite widget wrapping 2 Scale(s)
Its goal is to obtain two values defining a range narrower than the
range defined for both Scale(s), say '-from' and '-to' options.
url : www.cpan.org/authors/id/J/JP/JPVIDAL/Tk-MinMaxScale-0.05.readme
url : www.cpan.org/authors/id/J/JP/JPVIDAL/Tk-MinMaxScale-0.05.tar.gz
------------------------------
Date: Sat, 09 Nov 2002 13:14:46 +0100
From: =?ISO-8859-1?Q?Jens_Axel_S=F8gaard?= <usenet@jasoegaard.dk>
Subject: Re: A vision for Parrot
Message-Id: <3dccfcbb$0$200$edfadb0f@dread11.news.tele.dk>
A.M. Kuchling wrote:
> There's also the problem of motivation: who's going to write those
> translators?
...
> Guile programmers? If they're Guile programmers, they must like
> programming in Scheme. Why would they work on translators for languages
> they'll never use?
And Guile programmrs is the right choice of words. Most Scheme
programmers does not use Guile. In most cases there are better
alternatives such as DrScheme and Bigloo.
------------------------------
Date: Sat, 9 Nov 2002 10:33:43 -0800
From: "Linux.ie" <mail@eircom.net>
Subject: Re: Pause in perl ???
Message-Id: <aqikjv$bpj$1@dorito.esatclear.ie>
Thanks guys.And David K.Wall its not homework. IAM ONLY 14 years old. i dont
go to a Computer Science School !!!!
------------------------------
Date: Sat, 09 Nov 2002 15:54:50 GMT
From: Kirk Is <kirkspam@alienbill.com>
Subject: Re: Safest way to convert $d.cc to $DCC ?
Message-Id: <edaz9.288$Y2.11847@news.tufts.edu>
Tad McClellan <tadmc@augustmail.com> wrote:
> Kirk Is <kirkspam@alienbill.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.
> Use cents (integers) instead of dollars.
Yup.
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. And there may even be a way
to use format to get the DDDDDDCC notation I want in the query
itself.
Thanks!
--
QUOTEBLOG: http://kisrael.com SKEPTIC MORTALITY: http://kisrael.com/mortal
"How do we stop an elephant if it goes berserk? What do we do? Do we use
an AK-47? An M-16? An AR-15?... Frankly, would that stop an elephant?
I really doubt it. Do they have a bazooka?" --US Senator Bob Smith
------------------------------
Date: Sat, 09 Nov 2002 15:42:45 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Substrings
Message-Id: <3DCD2CD5.9050400@rochester.rr.com>
John Sellers wrote:
> Try
> /^ABC(...)*(PQR|XYZ)$/
>
That doesn't meet the OP's criteria of listing all the substrings which
match the pattern. In addition, it does not match the example string,
since the regex is anchored and the start of the example string doesn't
match.
--
Bob Walton
> Bob Walton wrote:
>
>> Kasp wrote:
>>
>> ...
>>
>>> I have to detect all possible substring combinations.
>>> The rules are:
>>> 1. The string starts with ABC
>>> 2. The string can end with PQR or XYZ
>>> 3. The string length should be a multiple of 3.
>>>
>>> Some examples are:
>>> ABCXYZ is Valid but ABCPXYZ or ABCPQXYZ are invalid because their
>>> length is not a multiple of 3.
>>>
>>> Apart from this, is it possible to detect all the substrings that
>>> match such a regular expression?
>>>
>>> Eg. PQABCGHKABCPQRAAAXYZ
>>> The answers for this are:
>>> ABCGHKABCPQR
>>> ABCGHKABCPQRAAAXYZ
>>> ABCPQR
>>> ABCPQRAAAXYZ
>>>
>>> Can someone please tell me what the regular expression will be? I have
>>> been trying a lot and the closet I could come was this
>>> ~/ABC(.*)?XYZ/;
>>
>>
>> ...
>>
>>
>>> Kasp.
>>>
>>
>>
>> $string="PQABCGHKABCPQRAAAXYZ";
>> @out=();
>>
>> $string=~/(ABC(?:...)*(?:PQR|XYZ))(?{push @out,$+})(?<=Q)/g;
>> print join "\n",@out;
>>
>
------------------------------
Date: Sat, 09 Nov 2002 16:44:17 +0100
From: Rick Jansen <rja@euronet.nl>
Subject: Re: wish fast method of counting of characters
Message-Id: <3DCD2D51.9050608@euronet.nl>
John Sellers wrote:
> I am going to be doing a lot of counting of characters from a large list
> of strings.
>
> What is the fastest way to do this? I know that unpack is pretty fast.
> But is this the way to do it?
>
> Here is some self contained working sample code, do I have as good an
> answer as I am going to get with pure Perl?
>
> #Typical string
> $nextString = "bbxslkfjlskjflksdjflksdjfljsdfljsdflkjsdlfkj\n";
>
>
> # START TIME CRITICAL CODE
> @asciiList = unpack( "C*", $nextString );
This works too, don't know what is faster though:
@asciiList = split(//,$nextString);
Rick Jansen
------------------------------
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 4089
***************************************