beginners@perl.org:

While coding some tests tonight, I discovered that Scalar::Util::blessed() considers Regexp references to be blessed.


Is this a bug or a feature?


TIA,

David



2012-01-22 21:07:57 dpchrist@p43400e ~/sandbox/perl
$ cat blessed
#! /usr/bin/perl
# $Id: blessed,v 1.1 2012-01-23 05:06:51 dpchrist Exp $
use strict;
use warnings;
use Test::More          tests => 11;
use Scalar::Util        qw( blessed );
our $foo;
ok( !blessed(undef),    'undefined value'                       ); #  1
ok( !blessed(''),       'empty string'                          ); #  2
ok( !blessed(0),        'zero'                                  ); #  3
ok( !blessed(1),        'one'                                   ); #  4
ok( !blessed(\0),       'scalar reference'                      ); #  5
ok( !blessed([]),       'array reference'                       ); #  6
ok( !blessed({}),       'hash reference'                        ); #  7
ok( !blessed(sub {}),   'code reference'                        ); #  8
ok( !blessed(*foo),     'glob reference'                        ); #  9
ok( ref(qr//) eq 'Regexp', 'qr// creates Regexp reference'      ); # 10
ok( !blessed(qr//),     'Regexp reference'                      ); # 11

2012-01-22 21:08:27 dpchrist@p43400e ~/sandbox/perl
$ perl blessed
1..11
ok 1 - undefined value
ok 2 - empty string
ok 3 - zero
ok 4 - one
ok 5 - scalar reference
ok 6 - array reference
ok 7 - hash reference
ok 8 - code reference
ok 9 - glob reference
ok 10 - qr// creates Regexp reference
not ok 11 - Regexp reference
#   Failed test 'Regexp reference'
#   at blessed line 18.
# Looks like you failed 1 test of 11.

2012-01-22 21:08:30 dpchrist@p43400e ~/sandbox/perl
$ perl -MScalar::Util -e 'print $Scalar::Util::VERSION, "\n"'
1.23

2012-01-22 21:08:34 dpchrist@p43400e ~/sandbox/perl
$ perl -v

This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi
(with 53 registered patches, see perl -V for more detail)

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


2012-01-22 21:08:37 dpchrist@p43400e ~/sandbox/perl
$ cat /etc/debian_version
6.0.3

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to