in reply to What are all the Perl data types?

my $regex = qr/x/;

I know $regex is a scalar, but the thing it refers to should be considered another type (which ref calls "Regexp").

Replies are listed 'Best First'.
Re^2: What are all the Perl data types?
by jettero (Monsignor) on May 03, 2007 at 11:03 UTC

    That's interesting. Perhaps, basically, it's whether or not one of the types above are blessed? Otherwise any blessed scalar is another type? That also makes me wonder if we could count iterators somehow.

    -Paul

      Otherwise any blessed scalar is another type?

      I tend to think that a scalar has a reference to a blessed thing rather than the scalar itself being blessed.

      my $unblessed = {}; my $blessed = $unblessed; bless $blessed, 'Holy::Holy'; printf "%s\n%s\n", ref $unblessed, ref $blessed; __END__ Holy::Holy Holy::Holy

      That's just a nitpick, though.

      I ordinarily wouldn't think of some user-created object as being a separate data type except that they can be overloaded to act just like one. Where does something like Math::BigInt fit in? I think this is a point on which reasonable people can disagree.

      That also makes me wonder if we could count iterators somehow.

      I don't know what you mean by this.

        Just a nitpick back: "sv_bless(SV* sv, HV* stash);" (perlguts); it really is the scalar that's blessed, rather than the other way around.

        I think this is a point on which reasonable people can disagree.

        I just recently read a discussion on (usenet or a mailinglist) about how the discussion of dynamically vs statically typed doesn't really make any sense unless you agree on the parameters before hand. I suspect this is sorta the same thing.

        -Paul

Re^2: What are all the Perl data types?
by blazar (Canon) on May 24, 2007 at 20:27 UTC
    I know $regex is a scalar, but the thing it refers to should be considered another type (which ref calls "Regexp").

    (Sorry for replying so late!) Indeed the return value of qr is a blessed reference. Thus these "objects" are real objects, and turn out to be autoboxed:

    use YAPE::Regex::Explain; sub Regexp::explain { print YAPE::Regex::Explain->new(shift)->explain; } qr/^.*?Foo(Bar){3,7}\d+/->explain;

    In Perl 6 everything is an object too, but currently this is not the case for simple scalars, arrays, etc. unless you use the very interesting autobox module, which used to require a patch, but doesn't anymore, last I checked.