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

[perl #53554] Range operator and magic

Thread Next
From:
Bram
Date:
April 30, 2008 07:21
Subject:
[perl #53554] Range operator and magic
Message ID:
rt-3.6.HEAD-20841-1209548118-108.53554-75-0@perl.org
# New Ticket Created by  Bram 
# Please include the string:  [perl #53554]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=53554 >


Double/Triple magic happens with the range operator.

$ cat range.pl
#!/usr/bin/perl -l

use strict;
use warnings;

use Tie::Scalar;
use base qw/Tie::StdScalar/;
my $count;
sub FETCH { $count++; ${ $_[0] } }

my $x;
tie $x, "main", 5;

$count = 0;
my @y1 = $x .. 6;
print "my \@y1 = \$x ..  6 = $count calls to FETCH";

$count = 0;
my @y2 = 4 .. $x;
print "my \@y2 =  4 .. \$x = $count calls to FETCH";

$count = 0;
my @y3 = $x .. $x;
print "my \@y3 = \$x .. \$x = $count calls to FETCH";


$ perl range.pl
my @y1 = $x ..  6 = 3 calls to FETCH
my @y2 =  4 .. $x = 3 calls to FETCH
my @y3 = $x .. $x = 6 calls to FETCH

(Tested with 5.8.8/5.10.0/blead)

I did try looking at it a while back but I gave up...


Kind regards,

Bram



Thread Next


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