develooper Front page | perl.perl5.porters | Postings from July 2008

overloading and formats (was Re: [perl #55668] 'eval'ing a certain format string segfaults perl)

Thread Previous
From:
Nicholas Clark
Date:
July 11, 2008 13:06
Subject:
overloading and formats (was Re: [perl #55668] 'eval'ing a certain format string segfaults perl)
Message ID:
20080711200636.GE94237@plum.flirble.org
formats consume their variables:

$ cat eat.pl
#!perl -w

$a = <<'EOT';
Pie
Good
EOT

print $a;
print "...\n";

formline '^*', $a;

print $a;
__END__
$ perl eat.pl 
Pie
Good
...
Good


What should the output of this be?

$ cat eat_overload.pl
#!perl -w
use strict;
package Pie;
use overload '""' => sub { return <<'EOT';
Pie
Good
EOT
};

sub new {
  bless [], shift;
}

package main;

$a = Pie->new;

print $a;
print "...\n";

formline '^*', $a;

print $a;
__END__


[No, I'm not going to give any clues. The current implementation is wrong, and
I don't know what the right answer is. Should the string return from an
overloaded reference be treated as a read only value?]

Nicholas Clark

Thread Previous


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