Re: parsing behavior of a subrule without/with a repetition specifier
[email protected] (Terrence Brannon)
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
On Thursday, November 8, 2001, at 11:25 AM, Damian Conway wrote:
>
> Akio asked:
>
>> more specifically, is the parsing behavior of
>>
>> program: statement
>>
>> equivalent to the counterpart of
>>
>> program: statement(1)
>>
>> EXCEPT for their resulting data structures (former: a scalar; latter: a
>> reference to an array) or something else?
>
> They are *supposed* to be identical, except for returned data structure.
> Did you find some other sense in which they were not?
>
I guess what Akio is saying (or what I get from what he is saying) is
that, in pure Perl, a repetition count of 1 returns the same data
structure as leaving off the repetition operator. However, P::RD is
different and hence surprising/non-intuitive in this respect:
use Data::Dumper;
my @a = (x);
my @b = (x) x 1;
warn Dumper(\@a, \@b);
my $x = 'x';
my $y = 'x' x 1;
warn Dumper($x, $y);
$VAR1 = [
'x'
];
$VAR2 = [
'x'
];
$VAR1 = 'x';
$VAR2 = 'x';