Re: Why does Tie::Simeple (scalar) work without real local data?



On 12/04/2006 10:52 AM, Dr.Ruud wrote:
Mumia W. (reading news) schreef:
[...]
Interestingly, even when I put the correct braces in, this weird code
(qr/[a-z]/ as the local data) still works as expected:
[... code snipped ...]


Before I recognized the problem, I used the source of Tie::Scalar to
convert your source to:

#!/usr/bin/perl -l
use strict ;
use warnings ;

tie my $incr, 'MyTest', -5 ;

print "Right now: $incr" ;
print "Right now: $incr" ;
print "Right now: $incr" ;
print "Right now: $incr" ;

untie $incr ;


package MyTest ;

sub TIESCALAR
{ my $class = shift
; my $instance = shift || undef
; return bless \$instance, $class
}

sub FETCH { ${$_[0]}++ }

sub STORE { $$_[0] = $_[1] }

sub DESTROY { undef ${$_[0]} }
__END__


Thanks. Now we might be getting somewhere. When I change -5 to qr/[a-z]/, I get wrong output:

Right now: (?-xism:[a-z])
Right now: 135580925
Right now: 135580926
Right now: 135580927

However, this output still confuses me. It looks like, when a regular expression variable is incremented, it changes into a number :-O

This code,

#!/usr/local/bin/perl5.9.4
my $sb = qr/[a-z]/;
print "sb before: $sb : type(@{[ ref $sb ]})\n";
$sb++;
print "sb after : $sb : type(@{[ ref $sb ]})\n";
printf "Perl: %vd\n", $^V;

prints this,

sb before: (?-xism:[a-z]) : type(Regexp)
sb after : 135686917 : type()
Perl: 5.9.4

Does anyone know if that is expected or desired behavior? This is not documented in perlop.


--
paduille.4060.mumia.w@xxxxxxxxxxxxx
.