|
Posted by A. Sinan Unur on April 14, 2008, 5:43 pm
Please log in for more thread options
spydox@gmail.com wrote in
news:e6278092-e663-4ea6-8f07-40d65faeb551
@f63g2000hsf.googlegroups.co
m:
[ please do not snip attributions ]
>> > I guess LLR parsing is to blame,
>>
>> I don't look at this as a parsing issue. Rather, it is a "the
>> universe must make sense" kind of issue: The first match does not
>> exist before the first match. That makes sense to me. It may not
>> make sense to you.
>>
>
> To me, like conventional pattern-recognition, of say two tanks
> next to each other, the system should accept it whether the match
> is described either way:
>
> find a tank with another identical tank to it's left
>
> *or*
>
> find a tank with another identical tank to it's right
>
>
> The system should have no *context-sensitivity* where only one of
> the two matches. Sure, internally an algorithm may be scanning L
> to R or R to L or whatever, but the user should not even be
> concerned with that, at least in this case. I still think it gave
> up too soon- it should have tried R to L (backtracking) when L to
> R failed.
What you seem to want is a "match two identical characters"
operator. For this particular case, you can achieve that by using:
=for example
my @strings = qw( 1222345 1233345 );
s/00|11|22|33|44|55|66|77|88|99// for @strings;
print "$_\n" for @strings;
=cut
When you use a character class, every element of that class is
considered equivalent to every other one. So, for example, when you
write
/\d/
that does find two characters that are in the same equivalence
class.
The tank analogy works perftectly here because there are no two
identical tanks in the world. Instead, there are equivalence classes
of tanks. Tanks that are the same model, tanks in the same unit etc.
If what you want is to say,
find a tank, then find another tank that is the same
model as the one you just found
well, that is equivalent to /(\d)/
J. D. Baldwin gives perfect examples of why /(\d)/ does not make
sense: Finding another tank in the same equivalence class as the one
you first found comes after first finding a tank.
> Just IMHO, thank-you for your thoughts. This area seems just a bit
> gray to me I'd be very interested in Damain or Mark's thoughts.
s/Damain/Damian/
My feeble mind looks at the following:
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
for ( my @a = qw( 1222345 1233345 ) ) {
s/(?<tank>\d)\K\k<tank>// and print "$_\n";
}
for ( my @a = qw( 1222345 1233345 ) ) {
s/(?<tank>\d)\K\k<tank>+// and print "$_\n";
}
for ( my @a = qw( 1222345 1233345 ) ) {
s/(?<tank>\d)\k<tank>// and print "$_\n";
}
__END__
thinks that the third one is the most natural (that is, find a tank,
then find another tank in the same equivalence class) to the other
ones.
Sinan
--
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
|