[31096] in Perl-Users-Digest
Perl-Users Digest, Issue: 2341 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 15 14:14:20 2009
Date: Wed, 15 Apr 2009 11:14:12 -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, 15 Apr 2009 Volume: 11 Number: 2341
Today's topics:
Recognizing a regex reference <devnull4711@web.de>
Re: Recognizing a regex reference <smallpond@juno.com>
Re: Recognizing a regex reference <ben@morrow.me.uk>
Re: Recognizing a regex reference <ben@morrow.me.uk>
Re: Recognizing a regex reference <smallpond@juno.com>
Re: Recognizing a regex reference <ben@morrow.me.uk>
Re: Recognizing a regex reference <devnull4711@web.de>
Re: Recognizing a regex reference <devnull4711@web.de>
Re: Recognizing a regex reference <ben@morrow.me.uk>
Re: Recognizing a regex reference <nospam-abuse@ilyaz.org>
What happens when undef replaces a placeholder in SQL q <md2600@gmail.com>
Re: What happens when undef replaces a placeholder in S <devnull4711@web.de>
Re: What happens when undef replaces a placeholder in S <md2600@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 15 Apr 2009 11:13:11 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Recognizing a regex reference
Message-Id: <74lmp7F14a713U2@mid.individual.net>
use strict;
use warnings;
use Scalar::Util;
my $ref = qr/x/;
print 'Test1: ',ref($ref),"\n";
$ref = bless $ref,'X';
print 'Test2: ',ref($ref),"\n";
print 'Test3: ',Scalar::Util::reftype($ref),"\n";
__END__
Test1: Regexp
Test2: X
Test3: SCALAR
How do I recognize a regex reference?
ref() works only with unblessed references.
reftype() doesn't help.
Any ideas?
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Wed, 15 Apr 2009 05:48:32 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Recognizing a regex reference
Message-Id: <b7d6d110-2dd0-47b3-97fd-bd2f8468edd0@z5g2000vba.googlegroups.com>
On Apr 15, 5:13=A0am, Frank Seitz <devnull4...@web.de> wrote:
> use strict;
> use warnings;
>
> use Scalar::Util;
>
> my $ref =3D qr/x/;
> print 'Test1: ',ref($ref),"\n";
> $ref =3D bless $ref,'X';
> print 'Test2: ',ref($ref),"\n";
> print 'Test3: ',Scalar::Util::reftype($ref),"\n";
>
> __END__
> Test1: Regexp
> Test2: X
> Test3: SCALAR
>
> How do I recognize a regex reference?
> ref() works only with unblessed references.
> reftype() doesn't help.
> Any ideas?
>
> Frank
** Untested **
use Acme::Damn;
$tmp =3D $ref;
curse($tmp);
print 'Test4: ',ref($tmp),"\n";
------------------------------
Date: Wed, 15 Apr 2009 13:54:22 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Recognizing a regex reference
Message-Id: <u02hb6-5r21.ln1@osiris.mauzo.dyndns.org>
Quoth Frank Seitz <devnull4711@web.de>:
> use strict;
> use warnings;
>
> use Scalar::Util;
>
> my $ref = qr/x/;
> print 'Test1: ',ref($ref),"\n";
> $ref = bless $ref,'X';
> print 'Test2: ',ref($ref),"\n";
> print 'Test3: ',Scalar::Util::reftype($ref),"\n";
>
> __END__
> Test1: Regexp
> Test2: X
> Test3: SCALAR
>
> How do I recognize a regex reference?
> ref() works only with unblessed references.
No. All qr// refs are blessed, by default into class "Regexp" as you
just demonstrated. If they didn't have stringify magic they'd look like
Regexp=SCALAR(0xdeadbeef) when printed.
> reftype() doesn't help.
> Any ideas?
Under 5.8 and earlier, don't rebless qr// refs. There really isn't any
other answer, short of using B to poke around looking for 'r' magic, or
doing the equivalent in XS.
5.10 has re::is_regexp, which reliably identifies a qr//. 5.12 will have
a new REGEXP scalar type, so reftype will return "REGEXP" for qr// refs.
Ben
------------------------------
Date: Wed, 15 Apr 2009 14:13:07 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Recognizing a regex reference
Message-Id: <343hb6-5r21.ln1@osiris.mauzo.dyndns.org>
Quoth smallpond <smallpond@juno.com>:
> On Apr 15, 5:13 am, Frank Seitz <devnull4...@web.de> wrote:
> > use strict;
> > use warnings;
> >
> > use Scalar::Util;
> >
> > my $ref = qr/x/;
> > print 'Test1: ',ref($ref),"\n";
> > $ref = bless $ref,'X';
> > print 'Test2: ',ref($ref),"\n";
> > print 'Test3: ',Scalar::Util::reftype($ref),"\n";
> >
> > __END__
> > Test1: Regexp
> > Test2: X
> > Test3: SCALAR
> >
> > How do I recognize a regex reference?
> > ref() works only with unblessed references.
> > reftype() doesn't help.
> > Any ideas?
>
> ** Untested **
>
> use Acme::Damn;
> $tmp = $ref;
> curse($tmp);
> print 'Test4: ',ref($tmp),"\n";
What did you think this would do? Under all released versions of perl,
qr// returns a SCALAR ref, so this just prints "SCALAR". (Bizarrely,
this also seems to kill the stringify magic, which I don't understand at
all.)
Ben
------------------------------
Date: Wed, 15 Apr 2009 08:04:28 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Recognizing a regex reference
Message-Id: <f9d7480d-d5cb-44b3-8020-6e7effbe6c84@t10g2000vbg.googlegroups.com>
On Apr 15, 9:13=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth smallpond <smallp...@juno.com>:
>
>
>
>
>
> > On Apr 15, 5:13=A0am, Frank Seitz <devnull4...@web.de> wrote:
> > > use strict;
> > > use warnings;
>
> > > use Scalar::Util;
>
> > > my $ref =3D qr/x/;
> > > print 'Test1: ',ref($ref),"\n";
> > > $ref =3D bless $ref,'X';
> > > print 'Test2: ',ref($ref),"\n";
> > > print 'Test3: ',Scalar::Util::reftype($ref),"\n";
>
> > > __END__
> > > Test1: Regexp
> > > Test2: X
> > > Test3: SCALAR
>
> > > How do I recognize a regex reference?
> > > ref() works only with unblessed references.
> > > reftype() doesn't help.
> > > Any ideas?
>
> > ** Untested **
>
> > use Acme::Damn;
> > $tmp =3D $ref;
> > curse($tmp);
> > print 'Test4: ',ref($tmp),"\n";
>
> What did you think this would do? Under all released versions of perl,
> qr// returns a SCALAR ref, so this just prints "SCALAR". (Bizarrely,
> this also seems to kill the stringify magic, which I don't understand at
> all.)
>
> Ben
I did not know that qr blessed its argument. It isn't
mentioned in perlop or perlre. My mistake.
------------------------------
Date: Wed, 15 Apr 2009 16:38:18 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Recognizing a regex reference
Message-Id: <akbhb6-dq41.ln1@osiris.mauzo.dyndns.org>
Quoth smallpond <smallpond@juno.com>:
> On Apr 15, 9:13 am, Ben Morrow <b...@morrow.me.uk> wrote:
> >
> > What did you think this would do? Under all released versions of perl,
> > qr// returns a SCALAR ref, so this just prints "SCALAR". (Bizarrely,
> > this also seems to kill the stringify magic, which I don't understand at
> > all.)
>
> I did not know that qr blessed its argument. It isn't
> mentioned in perlop or perlre. My mistake.
You're right, it doesn't seem to be mentioned in the standard
documentation. perldoc -f ref has an obscure reference to "Regexp", as
though it's a builtin type like SCALAR or HASH rather than simply a
class, which isn't exactly helpful. IIRC it's explained properly in the
Camel book, but I don't have a copy to hand.
You can see the 'normal' stringification with overload::StrVal:
perl -Moverload -le'print overload::StrVal(qr/x/)'
Regexp=SCALAR(0x81048cc)
(under 5.12 this will become Regexp=REGEXP(0x81048cc) of course) or you
can use Scalar::Util::blessed and ::reftype to get the class and type
seperately. As a general rule most uses of 'ref' ought to be either
'blessed' or 'reftype' instead, if not ->isa or ->DOES.
Ben
------------------------------
Date: Wed, 15 Apr 2009 18:16:36 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Recognizing a regex reference
Message-Id: <74mfj4F14a713U4@mid.individual.net>
Ben Morrow wrote:
> Quoth Frank Seitz <devnull4711@web.de>:
>> use strict;
>> use warnings;
>>
>> use Scalar::Util;
>>
>> my $ref = qr/x/;
>> print 'Test1: ',ref($ref),"\n";
>> $ref = bless $ref,'X';
>> print 'Test2: ',ref($ref),"\n";
>> print 'Test3: ',Scalar::Util::reftype($ref),"\n";
>>
>> __END__
>> Test1: Regexp
>> Test2: X
>> Test3: SCALAR
>>
>> How do I recognize a regex reference?
>> ref() works only with unblessed references.
>
> No. All qr// refs are blessed, by default into class "Regexp" as you
> just demonstrated. If they didn't have stringify magic they'd look like
> Regexp=SCALAR(0xdeadbeef) when printed.
>
>> reftype() doesn't help.
>> Any ideas?
>
> Under 5.8 and earlier, don't rebless qr// refs. There really isn't any
> other answer, short of using B to poke around looking for 'r' magic, or
> doing the equivalent in XS.
>
> 5.10 has re::is_regexp, which reliably identifies a qr//. 5.12 will have
> a new REGEXP scalar type, so reftype will return "REGEXP" for qr// refs.
Thank you for the very well-informed answer.
If Regexp is the base class of all regexes, then $ref->isa('Regexp')
is the test I am looking for, i think. If qr// is blessed to another class,
this should be a subclass of Regexp of course.
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Wed, 15 Apr 2009 18:55:41 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Recognizing a regex reference
Message-Id: <74mhsdF14a713U5@mid.individual.net>
Ben Morrow wrote:
> Quoth smallpond <smallpond@juno.com>:
>>
>> use Acme::Damn;
>> $tmp = $ref;
>> curse($tmp);
>> print 'Test4: ',ref($tmp),"\n";
>
> What did you think this would do? Under all released versions of perl,
> qr// returns a SCALAR ref, so this just prints "SCALAR". (Bizarrely,
> this also seems to kill the stringify magic, which I don't understand at
> all.)
The stringification is realized through a method. When the
class membership is removed from an object, then the stringification
method is lost, too.
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Wed, 15 Apr 2009 18:35:09 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Recognizing a regex reference
Message-Id: <dfihb6-8i61.ln1@osiris.mauzo.dyndns.org>
Quoth Frank Seitz <devnull4711@web.de>:
> Ben Morrow wrote:
> > Quoth smallpond <smallpond@juno.com>:
> >>
> >> use Acme::Damn;
> >> $tmp = $ref;
> >> curse($tmp);
> >> print 'Test4: ',ref($tmp),"\n";
> >
> > What did you think this would do? Under all released versions of perl,
> > qr// returns a SCALAR ref, so this just prints "SCALAR". (Bizarrely,
> > this also seems to kill the stringify magic, which I don't understand at
> > all.)
>
> The stringification is realized through a method. When the
> class membership is removed from an object, then the stringification
> method is lost, too.
No. I said 'magic' not 'overloading', and I meant it. The
stringification is *not* performed by a method, indeed the Regexp class
doesn't have any methods under normal circumstances. It is in fact
performed inside sv.c:Perl_sv_2pv_flags, and the code apparently
requires the SV to be an object as well as to carry 'r' magic: I don't
know why.
To see this is quite different from ordinary stringify overloading, try
this:
perl -le'print bless qr/x/'
(?-xism:x)
If this had been ordinary overloading the reblessing would have removed
the overload, and we would have got main=SCALAR(0xdeadbeef).
Looking at the code, it appears this will change in 5.12 with the new
REGEXP type, and REGEXP refs will always stringify as patterns
regardless of their blessedness.
Ben
------------------------------
Date: Wed, 15 Apr 2009 18:00:17 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Recognizing a regex reference
Message-Id: <slrnguc8hp.4jb.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-15, Frank Seitz <devnull4711@web.de> wrote:
> How do I recognize a regex reference?
> ref() works only with unblessed references.
When I first implemented it, it must have been of class Regexp - for
performance reasons. It might have been that speed is not considered
an issue with newer perls...
Hope this helps,
Ilya
------------------------------
Date: Wed, 15 Apr 2009 08:22:41 -0700 (PDT)
From: Mark <md2600@gmail.com>
Subject: What happens when undef replaces a placeholder in SQL query?
Message-Id: <29750c41-ddb9-41f4-b5c4-ed07e60458d4@k38g2000yqh.googlegroups.com>
What happens when a placeholder in an SQL statement is replaced by
undef/NULL?
E.g.,
SELECT fullname FROM people WHERE age = ?
$sth->execute()
Does this depend on the database? (DB2 in this case). Is this just an
error?
Thanks,
Mark
------------------------------
Date: Wed, 15 Apr 2009 18:00:33 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: What happens when undef replaces a placeholder in SQL query?
Message-Id: <74mel1F14a713U3@mid.individual.net>
Mark wrote:
> What happens when a placeholder in an SQL statement is replaced by
> undef/NULL?
>
> E.g.,
>
> SELECT fullname FROM people WHERE age = ?
>
> $sth->execute()
>
> Does this depend on the database? (DB2 in this case). Is this just an
> error?
No, it's not an error. It's simply an unsatisfiable condition,
because EXPR = NULL is false. I.e. you get an empty result set.
I think this behavior is the same under all relational database systems.
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Wed, 15 Apr 2009 09:28:57 -0700 (PDT)
From: Mark <md2600@gmail.com>
Subject: Re: What happens when undef replaces a placeholder in SQL query?
Message-Id: <fc31c378-0c10-4318-b21c-5afc948f9481@q2g2000vbr.googlegroups.com>
On Apr 15, 12:00=A0pm, Frank Seitz <devnull4...@web.de> wrote:
> No, it's not an error. It's simply an unsatisfiable condition,
> because EXPR =3D NULL is false. I.e. you get an empty result set.
> I think this behavior is the same under all relational database systems.
Thanks Frank. We have a webapp that is executing a large/long query.
The DBA can 'see' the query as it is being executed, and it has a
number of '?' placeholders still in it. Some of the placeholder have
been replaced with specific values for the query, but a number of them
are still '?'. When this query is running, load on the DB server
shoots up, application responsiveness tanks, etc. So we are trying to
pinpoint the source of the problem.
Cheers,
Mark
------------------------------
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 V11 Issue 2341
***************************************