Quoting Ken Williams <[EMAIL PROTECTED]>:
hmm, ok
so if i do one test that actually matches late in my string and later do a test
that would match earlier, the latter will never match ?
i didn't know that; to me it doesn't sound logical. to me i'm doing a complete
fresh test in the regexp so if i had a match in a previous regexp test it
shouldn't matter since the string doesn't change and even the pos() shouldn't
change because to me both are completely "fresh"
anyway, thats how it is ...
./a
sounds
> Hi Allan,
>
> No bug; here's a simpler example that shows what's going on.
>
> $str = "one two";
> if ($str =~ /one/g) { print "Found one\n" }
> print "pos(\$str): ", pos($str), "\n";
> if ($str =~ /two/g) { print "Found two\n" }
> print "pos(\$str): ", pos($str), "\n";
>
> $str = "one two";
> if ($str =~ /two/g) { print "Found two\n" }
> print "pos(\$str): ", pos($str), "\n";
> if ($str =~ /one/g) { print "Found one\n" }
> print "pos(\$str): ", pos($str), "\n";
>
> -Ken
>
>
> On May 17, 2004, at 2:35 PM, allan juul wrote:
>
> > hi
> >
> > i have some difficulty with a rather simple loop and simple RegExp:
> >
> >
> > please try the following code two times - one with no command line
> > arguments and one with a true argument [the latter call will reverse
> > the sorting of the hash keys]
> >
> > for example:
> >
> > $ net.pl
> > $ net.pl 1
> >
> >
> > the funny thing is that even that perl guarantees me that the two
> > strings $str and str2 are equal (which they should be since i assign
> > them to each other just before the "eq" test), the RegExp only match
> > when the keys in the hash are alphabetically sorted
> >
> > can anybody explain this ?
> >
> > thanks
> > ./allan
> >
> > #######################################
> > use strict;
> >
> > my %maps = (
> > i => 'somestring',
> > j => 'someother',
> > );
> >
> >
> > my $str = q(
> > I:somestring
> > J:someother
> > );
> >
> > foreach my $key (sort by_str keys %maps ) {
> > my $str2 = $str;
> >
> > if ($str eq $str2) {
> > print "\n\tGoing to testing the key $key\n\tApparently the
> > varibale \$str is identical to \$str2\n\n";
> >
> > }
> >
> > print "Testing \$str ...\n";
> > if ($str =~ m/^$key.+/mig) {
> > print "\tA match for \$str\n";
> > } else {
> > print "\tHmm no match in \$str\n";
> > }
> >
> > print "Testing \$str2 ...\n";
> > if ($str2 =~ m/^$key.+/mig) {
> > print "\tA match for \$str2\n";
> > } else {
> > print "\tHmm no match in \$str2\n";
> > }
> > }
> >
> > sub by_str {
> > if ($ARGV[0]) {
> > ($b cmp $a)
> > } else {
> > ($a cmp $b)
> > }
> > }
> >
> >
> >
> >
>
>
--