develooper Front page | perl.perl5.porters | Postings from January 2004

Scalar::Util and UNIVERSAL::isa disagree about qr//

Thread Next
From:
Tels
Date:
January 11, 2004 03:09
Subject:
Scalar::Util and UNIVERSAL::isa disagree about qr//
Message ID:
200401111208.45720@bloodgate.com
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

I think Scalar::Util has a bug, it reports reftype(qr//) as "SCALAR", while it 
should return "REGEXP". In addition, UNIVERSAL::isa() thinks a qr// object is 
a 'Regexp' (note the mixed case!!) _and_ a 'SCALAR'.

% cat util.pl
#!/usr/bin/perl -w

use Scalar::Util qw/reftype/;
use strict;

my $x = \"12";

printit(\"12");
printit( qr/^(foo|bar)\$/);

sub printit
  {
  my $x = $_[0];
  print join ("\t",
        $x,
        reftype($x),
        ref($x),
        UNIVERSAL::isa($x,'SCALAR') || 'not SCALAR',
        UNIVERSAL::isa($x,'REGEXP') || 'not REGEXP',
        UNIVERSAL::isa($x,'Regexp') || 'not Regexp',
        ),"\n";
  }
% perl util.pl
SCALAR(0x81585bc)       SCALAR  SCALAR  1       not REGEXP      not Regexp
(?-xism:^(foo|bar)\$)   SCALAR  Regexp  1       not REGEXP      1

But it could be a feature :)

Best wishes,

Tels

- -- 
 Signed on Sun Jan 11 12:07:25 2004 with key 0x93B84C15.
 Visit my photo gallery at http://bloodgate.com/photos/
 PGP key on http://bloodgate.com/tels.asc or per email.

 "My glasses, my glasses. I cannot see without my glasses." - "My glasses,
 my glasses. I cannot be seen without my glasses."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBQAEuvHcLPEOTuEwVAQG2zwf+O0Myv60WRns0SoWJvrj9HODTbxds534w
92c0JzdcC8bUd3U5pJpXJ9qwho9zGpmD+imPe5jMTwQ8wbdU9trQthDaDgsKumNk
IaplGuwg2wPttShcdKR5GjvkQD3nD/TyTtsey5m6tV6IpAvdu0BZ4CAgHMBaNR6a
Nh+ftGCEOV2q3bK8QPPsVpU1UE7Spr71WklkTavGn/bgxuzzMYPCRO6eCvo0PC00
bNd3DT+pCj8ZVSmS9JE/XLNkgsEvjFg6YCj6D/hhs7VHEB39kTnfg3WW79n45kXR
DlUZMTRfbrbMKbPk2o8SliLq+ckJ1CheFxKLGu78KT9j6RHjO8dxOA==
=LF56
-----END PGP SIGNATURE-----


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About