[23671] in Perl-Users-Digest
Perl-Users Digest, Issue: 5878 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 1 14:05:40 2003
Date: Mon, 1 Dec 2003 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 Mon, 1 Dec 2003 Volume: 10 Number: 5878
Today's topics:
[ANNOUNCE] Apache::SessionManager 1.00 (mp1/mp2 compati <enrico@sorcinelli.it>
Re: Array Indexing problem (Harish)
cannot match pattern <joeminga@yahoo.com>
Re: cannot match pattern <usenet@morrow.me.uk>
Re: cannot match pattern <joeminga@yahoo.com>
Re: cannot match pattern (Tad McClellan)
Re: cannot match pattern <usenet@morrow.me.uk>
Re: cannot match pattern <xx087@freenet.carleton.ca>
Re: count of 1s in a binary number (David Combs)
Re: Deleting tmp-files of CGI.pm upload() <randy@theoryx5.uwinnipeg.ca>
Re: Dynamic check boxes from two arrays <usenet@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 1 Dec 2003 17:03:17 GMT
From: Enrico Sorcinelli <enrico@sorcinelli.it>
Subject: [ANNOUNCE] Apache::SessionManager 1.00 (mp1/mp2 compatible)
Message-Id: <Hp88ED.1H7x@zorch.sf-bay.org>
The uploaded file
Apache-SessionManager-1.00.tar.gz
has entered CPAN as
file: $CPAN/authors/id/E/EN/ENRYS/Apache-SessionManager-1.00.tar.gz
size: 27856 bytes
md5: e88605e7130611ff4ea84caadba8e1fc
This is the first both mod_perl 1.0 and 2.0 compatible release.
Changes from previous version
-----------------------------
+ Added mod_perl 2 and mod_perl 1 full compatibility
+ Added OO interface
+ Added new cookpod sections:
- "Using Apache::SessionManager without root privileges"
- "Using Apache::SessionManager with Apache::DBI"
- "Expiration policies on the client side"
+ Added t/lib/PerlEnvOO.pm simple mod_perl handler to test OO interface
! Updated Makefile.PL in order to:
- accept command line switch '-n' which
doesn't ask at prompt and doesn't run live Apache tests. This is to pack
easier this package for Debian (suggested by Krzysztof Krzyzaniak
<eloy@debian.org>)
- check correctly environment: mod_perl generation
anded test suite. Added messages before configuring tests
- added httpd.conf extra lines for testing with Apache::DBI
! Bug fix: SessionManagerExpire: '0' => (none|no|disabled) value means no
expiration time
! Moved tests to run only under Apache::testold mod_perl 1 test suite
! Ported t/lib/*.pm sample modules to work either with mod_perl 1.0 and 2.0
! Updated PODS
See perldoc Apache::SessionManager for module documentation and use
See perldoc Apache::SessionManager::cookpod for more info about module use
Any comment and/or criticism are welcome :-)
by
- Enrico
------------------------------
Date: 1 Dec 2003 09:31:54 -0800
From: harish_recian@yahoo.com (Harish)
Subject: Re: Array Indexing problem
Message-Id: <a3ef9093.0312010931.306c28c6@posting.google.com>
Hi ,
Thanks a lot for all the information.I finally figured out the problem
anfd my code is working fine.
Thanks
Harish
"John W. Krahn" <krahnj@acm.org> wrote in message news:<3FC8F112.7A8391D8@acm.org>...
> Harish wrote:
> >
> > I am having a problem while indexing an element in perl.
> >
> > Problem Details:
> >
> > [snip]
> >
> > if i have $x=4 then when i say $temp[$x] it prints the previous line
> > but when i say $temp[4] it prints the line that i'm interested in.
> > This does not happen for all the lines.It is just happening for few
> > lines.
>
> You are running in to the classical problem of representing floating
> point numbers on a binary computer. When you use a floating point
> number as an array index, perl will convert it to an integer by removing
> everything after the decimal point.
>
> $ perl -e'
> my @array = 0 .. 10;
> my $x = 4 - 1e-15;
> print "$x\n";
> printf "%.18f\n", $x;
> print "$array[$x]\n";
> '
> 4
> 3.999999999999999112
> 3
>
>
> This FAQ from perlfaq4.pod will help explain it:
>
> perldoc -q "Why am I getting long decimals"
>
>
>
> John
------------------------------
Date: Mon, 1 Dec 2003 12:43:25 -0500
From: "Domenico Discepola" <joeminga@yahoo.com>
Subject: cannot match pattern
Message-Id: <w8Lyb.113327$PD3.5786709@nnrp1.uunet.ca>
Hello. I cannot match $ex in the following example. I'm reading records
from a text file (field seperator "\n" record seperator "\x0c"). I
simulated 1 incoming record in the $a variable. Unfortunately, I wasn't
able to get any insight from perldoc... Any help would be appreciated.
#!perl
use strict;
use warnings;
my $ex = '$Conflict: ';
my $a = "field1: test1\n\$Conflict: 1\nfield 3: test3\x0c";
print "[$a]\n";
if ( $a =~ /$ex/ ) {
print "found\n";
} else {
print "not found\n";
}
------------------------------
Date: Mon, 1 Dec 2003 18:21:38 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: cannot match pattern
Message-Id: <bqg0ri$rqt$1@wisteria.csv.warwick.ac.uk>
"Domenico Discepola" <joeminga@yahoo.com> wrote:
> Hello. I cannot match $ex in the following example. I'm reading records
> from a text file (field seperator "\n" record seperator "\x0c"). I
> simulated 1 incoming record in the $a variable. Unfortunately, I wasn't
> able to get any insight from perldoc... Any help would be appreciated.
>
> #!perl
> use strict;
> use warnings;
>
> my $ex = '$Conflict: ';
> my $a = "field1: test1\n\$Conflict: 1\nfield 3: test3\x0c";
> print "[$a]\n";
>
> if ( $a =~ /$ex/ ) {
> print "found\n";
> } else {
> print "not found\n";
> }
Have you run this code? It works for me.
As a side issue, it's best not to use $a or $b: see perlvar.
Ben
--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
ben@morrow.me.uk
------------------------------
Date: Mon, 1 Dec 2003 13:25:09 -0500
From: "Domenico Discepola" <joeminga@yahoo.com>
Subject: Re: cannot match pattern
Message-Id: <FLLyb.113338$PD3.5787141@nnrp1.uunet.ca>
"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:bqg0ri$rqt$1@wisteria.csv.warwick.ac.uk...
>
> "Domenico Discepola" <joeminga@yahoo.com> wrote:
> > Hello. I cannot match $ex in the following example. I'm reading
records
> > from a text file (field seperator "\n" record seperator "\x0c"). I
> > simulated 1 incoming record in the $a variable. Unfortunately, I wasn't
> > able to get any insight from perldoc... Any help would be appreciated.
> >
> > #!perl
> > use strict;
> > use warnings;
> >
> > my $ex = '$Conflict: ';
> > my $a = "field1: test1\n\$Conflict: 1\nfield 3: test3\x0c";
> > print "[$a]\n";
> >
> > if ( $a =~ /$ex/ ) {
> > print "found\n";
> > } else {
> > print "not found\n";
> > }
>
> Have you run this code? It works for me.
>
> As a side issue, it's best not to use $a or $b: see perlvar.
>
> Ben
>
Yes - I ran this code on my w2k and redhat boxes and perl still does not
match the expression...
Point taken on the $a $b vars...
------------------------------
Date: Mon, 1 Dec 2003 12:41:31 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: cannot match pattern
Message-Id: <slrnbsn2qr.3m5.tadmc@magna.augustmail.com>
Domenico Discepola <joeminga@yahoo.com> wrote:
> I cannot match $ex in the following example.
> my $ex = '$Conflict: ';
> if ( $a =~ /$ex/ ) {
> print "found\n";
Your pattern says that you want to match "Conflict: " _after_
the end of the string.
That is never going to happen.
my $ex = '\$Conflict: ';
or
if ( $a =~ /\Q$ex/ ) {
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 1 Dec 2003 18:43:52 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: cannot match pattern
Message-Id: <bqg258$slv$1@wisteria.csv.warwick.ac.uk>
"Domenico Discepola" <joeminga@yahoo.com> wrote:
> "Ben Morrow" <usenet@morrow.me.uk> wrote in message
> news:bqg0ri$rqt$1@wisteria.csv.warwick.ac.uk...
> >
> > "Domenico Discepola" <joeminga@yahoo.com> wrote:
> > > Hello. I cannot match $ex in the following example. I'm reading
> records
> > > from a text file (field seperator "\n" record seperator "\x0c"). I
> > > simulated 1 incoming record in the $a variable. Unfortunately, I wasn't
> > > able to get any insight from perldoc... Any help would be appreciated.
> > >
> > > #!perl
> > > use strict;
> > > use warnings;
> > >
> > > my $ex = '$Conflict: ';
> > > my $a = "field1: test1\n\$Conflict: 1\nfield 3: test3\x0c";
> > > print "[$a]\n";
> > >
> > > if ( $a =~ /$ex/ ) {
> > > print "found\n";
> > > } else {
> > > print "not found\n";
> > > }
> >
> > Have you run this code? It works for me.
>
> Yes - I ran this code on my w2k and redhat boxes and perl still does not
> match the expression...
My apologies: I am an idiot. I made the reverse of the usual mistake
and retyped my test, with a typo... :(
The trouble is that your regex comes out as /$Conflict: /, which
attempts to match 'end-of-string, followed by Conflict: '. This
doesn't match. What you want is
if ( $a =~ /\Q$ex/ ) {
which will quote the $ for you. \Q is documented in perlop, under
"Quote and Quote-like Operators".
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=> (Kate Rusby)
------------------------------
Date: 1 Dec 2003 18:44:38 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: cannot match pattern
Message-Id: <slrnbsn326.t4g.xx087@smeagol.ncf.ca>
Domenico Discepola <joeminga@yahoo.com> wrote:
> my $ex = '$Conflict: ';
> my $a = "field1: test1\n\$Conflict: 1\nfield 3: test3\x0c";
> print "[$a]\n";
>
> if ( $a =~ /$ex/ ) {
The dollar sign in $ex is the problem. Perl's trying to match
'Conflict: ' after the end of the line.
use: $ex = '\$Conflict: ';
or: $ex = quotemeta '$Conflict: ';
or: $a =~ /\Q$ex/
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Mon, 1 Dec 2003 17:17:18 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: count of 1s in a binary number
Message-Id: <bqft2t$26c$1@reader2.panix.com>
In article <boj8vt$iui$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
>> On Fri, 07 Nov 2003 18:36:24 +1100, Fred <fJogham@yahoo.com> wrote:
>>
>> >the main issue is how to get the sub to deal with both data types and
>> >give the expected results which is the count of "1" in the string or
>> >array with out writeing 2 subs
>
>[snip]
>
>> If you choose to use numbers instead of bitstrings a less
>> Perl-specific way to count '1's is could be:
>>
>> sub size1 {
>> # Recursive approach, terse and elegant IMHO.
>> # An iterative one is OK as well.
>> my $n=shift;
>> return 0 unless $n;
>> return ($n&1) + size1($n>>1);
>> }
>
>That counts the bits of an n-bit number in n steps. There is an old trick
>in the dying art of bit-fiddling that allows to count them in as many steps
>as there are one-bits. That is a significant advantage if the numbers
>involved are small (or sparse, bit-wise).
>
>The trick is to isolate the least significant one-bit in a number
>in one step. This is essentially done by subtracting 1 from the number.
>Beginning from the least significant bit, this builds a bridge of
<SNIP>
Where'd you find that, HAKMEM maybe?
David
------------------------------
Date: Mon, 1 Dec 2003 09:34:50 -0600
From: "Randy Kobes" <randy@theoryx5.uwinnipeg.ca>
Subject: Re: Deleting tmp-files of CGI.pm upload()
Message-Id: <vcJyb.33792$MW5.49671@news1.mts.net>
"Jo Oberman" <johanoberm@gmx.de> wrote in message
news:35uksvg5v5jbo3vpemh7h45jluuootc7ea@4ax.com...
> > .... saved, but that is it. It is removed automatically, so there is no
need
> >to attempt that.
>
> Unfortunately, not.
> Using my configuration (Windows XP, Apache 1.3.27, Perl 5.6.1, CGI.pm
V2.93),
> the CGItemp-files are left in my directoy c:\temp.
> So I have to help myself.
>
> Any idea's how to delete them?
I think this is a known bug in CGI.pm on Windows. See
http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=106137320903099&w=2
best regards,
randy kobes
------------------------------
Date: Mon, 1 Dec 2003 14:12:35 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Dynamic check boxes from two arrays
Message-Id: <bqfi8j$f8q$1@wisteria.csv.warwick.ac.uk>
"Bigus" <someone@somewhere.com> wrote:
> > The biggest problem is that you are not using the natural
> > representation for the data-type. In Perl the natural representation
> > of a set is a hash with keys but no data. Replacing @DaysPlayerPlays
> > with %DaysPlayerPlays we get:
> >
> > if ( exists $DaysPlayerPlays{$DaysPlayed} ) {
> >
> > Or, if you prefer, a hash where all the data items are 1.
> >
> > if ( $DaysPlayerPlays{$DaysPlayed} ) {
>
> Yeah that would be easiest.. sometimes though the "natural" data-type is not
> always the most "comfortable" to declare, eg:
>
> He was using an array to hold the days:
>
> my @DaysPlayerPlays = qw(Mon Tue Wed Sat);
>
> but to declare that as a has you'd, correct me if I'm wrong, have to do sth
> like this:
>
> my %DaysPlayerPlays = (Mon=>'',Tue=>'',Wed=>'',Sat=>'');
my %DaysPlayerPlays;
@DaysPlayerPlays{qw/Mon Tue Wed Sat/} = ();
Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
------------------------------
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 5878
***************************************