Re: Why does Tie::Simeple (scalar) work without real local data?
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 05 Dec 2006 09:32:11 GMT
Mumia W. (reading news) wrote:
Interesting. Perl references can become numbers but can't return to
references again. That's not quite like C :-)
But I still wonder why this program works so well:
#!/usr/bin/perl
use strict;
use warnings;
use Tie::Simple;
my $sb = qr/[a-z]/;
tie my $incr, 'Tie::Simple', $sb,
FETCH => sub { ${$_[0]}++ },
STORE => sub { ${$_[0]} = $_[1] };
print "sb1: $sb\n";
print "Right now: $incr\n";
print "Right now: $incr\n";
print "Right now: $incr\n";
print "Right now: $incr\n";
print "sb2: $sb\n";
untie $incr;
-------------
That program prints this:
sb1: (?-xism:[a-z])
Right now: 0
Right now: 1
Right now: 2
Right now: 3
sb2: Regexp=SCALAR(0x814cc6c)
The regular expression is somehow changed, and it seems to be storing my
value in it, but compiled regular expressions can't contain numbers--can
they?
You are dereferencing the value in $sb so you are not modifying its value but
what its value points to.
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- References:
- Why does Tie::Simeple (scalar) work without real local data?
- From: Mumia W. (reading news)
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Dr.Ruud
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Mumia W. (reading news)
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Dr.Ruud
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Mumia W. (reading news)
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: John W. Krahn
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Mumia W. (reading news)
- Why does Tie::Simeple (scalar) work without real local data?
- Prev by Date: Re: Why does Tie::Simeple (scalar) work without real local data?
- Next by Date: Sort::Maker : anonymous sub is compiled outside of my module
- Previous by thread: Re: Why does Tie::Simeple (scalar) work without real local data?
- Next by thread: Re: Why does Tie::Simeple (scalar) work without real local data?
- Index(es):