On Sun, 6 Aug 2000 18:28:29 -0800, Michael Fowler wrote:
print $pw;
print scalar $pw;
These resulting in a $pw-STRINGIFY or $pw-TO_STRING call is also
confusing; neither are being used as strings.
Oh yes they are.
$^W = 1;
my $x;
print $x;
This complains of
At 11:36 PM 8/6/00 +, you wrote:
I suggest that objects provide a default method called CSCALAR that
determines what they produce in a scalar context. When stringified, an
object would automatically call its CSCALAR function and return the
correct value.
I don't see in here how an object
Objects should have builtin string SCALAR method
Sorry if I'm just being dumb, but... don't we already have this by
overloading the stringifying operator q{''}? How is the proposed SCALAR
method different?
On Sun, 06 Aug 2000 16:43:36 -0700, Peter Scott wrote (in part):
Peter Call me old-fashioned, but I don't see what's wrong with
Peter use overload '""' = sub { $_[0]-to_string };
Peter for anything that wants to take such a relatively odd
Peter action.
Larry's commented (in p5p) on his own
I don't see in here how an object tells the difference between being in
scalar context and being in string context.
Think tie(). It wouldn't necessarily be the object that makes the
decision.
for anything that wants to take such a relatively odd action.
As Spider notes, this isn't really
Larry's commented (in p5p) on his own experience in trying to
have properly "stringified" objects. He wound up with a bunc of
classes doing exactly what you suggest, which is using the
existing overload mechanism *for just that one operation*. He
speculated then that this particular one
Nathan Wiger wrote:
$pw = getpwnam('nwiger');
print "$pw"; # calls $pw-SCALAR, which prints 'nwiger'
die "Bad group" unless $pw-gid == 100;
I'm ashamed that this feature would mess with my (bad?) habit of
re-writing "$pw" to just $pw on the assumption that whoever wrote
it
At 04:02 AM 8/7/00 +0200, Bart Lateur wrote:
STRINGIFY would have my vote. "It's a string!!!". A string is a very
specific subtype of scalar.
How about TO_STRING? Little less geeky.
How would this play with overload.pm? What if that also specifies a
stringify routine? Which one should win?
Or just STRING. It's a verb to, you know ;-)
Yeah, I think this is best. SCALAR isn't real accurate anyways. I'll
change it in v2.
-Nate