in reply to Re: Why reftype and blessed are making my life harder than it needs to be
in thread Why reftype and blessed are making my life harder than it needs to be
Since the empty string is a valid blessed classNo, it's not. If the second argument of bless is the empty string, the thing being blessed is blessed into main. If you turn on warnings, Perl will tell you so.
Otherwise, how would you distinguish the empty blessing from the unblessed, religious overtones notwithstanding?That's easy. blessed returns main in the first case, and so does ref. ref returns the empty string if its argument isn't a reference - and that's never ambigious, and hence there would be any ambiguity if blessed would do the same.
#!/usr/bin/perl use strict; use warnings; use Scalar::Util 'blessed'; my $ref = bless [], ""; print ref $ref, "\n"; print blessed $ref, "\n"; __END__ Explicit blessing to '' (assuming package main) at "..." line 8. main main
Perl --((8:>*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Why reftype and blessed are making my life harder than it needs to be
by diotalevi (Canon) on Feb 10, 2006 at 05:16 UTC | |
by jdhedden (Deacon) on Feb 10, 2006 at 18:09 UTC | |
by diotalevi (Canon) on Feb 10, 2006 at 21:15 UTC | |
by Perl Mouse (Chaplain) on Feb 11, 2006 at 19:53 UTC | |
by diotalevi (Canon) on Feb 12, 2006 at 04:27 UTC | |
Re^3: Why reftype and blessed are making my life harder than it needs to be
by ysth (Canon) on Feb 10, 2006 at 04:43 UTC |
In Section
Meditations