Thread pos($string) zwischen //g Regexes in Schleife? (9 answers)
Opened by GoodFella at 2007-03-27 18:55

PerlProfi
 2007-03-28 16:41
#75452 #75452
User since
2006-11-29
340 Artikel
BenutzerIn
[default_avatar]
[quote=GoodFella,28.03.2007, 13:36]Dass die Position bei Listenkontext in $+[0] steht, davon finde ich aber nichts.. In $+[1] befindet sich nach meinen Tests ($+[0] - 1) .. keine Ahnung welchen Zweck das hat.. oder hab ich was überlesen? :)[/quote]
Du hast dir nur die falsche Variable angesehen:
Quote
@LAST_MATCH_END
@+

This array holds the offsets of the ends of the last successful submatches in the currently active dynamic scope. $+[0] is the offset into the string of the end of the entire match. This is the same value as what the pos function returns when called on the variable that was matched against. The nth element of this array holds the offset of the nth submatch, so $+[1] is the offset past where $1 ends, $+[2] the offset past where $2 ends, and so on. You can use $#+ to determine how many subgroups were in the last successful match. See the examples given for the @- variable.


Aber ich verstehe nicht, wieso die Position nicht zurück gesetzt wird, folgendes funktioniert nämlich wie erwartet:
Code: (dl )
1
2
3
4
5
6
7
8
#!/usr/bin/perl
use strict;
use warnings 'all';

my $str = 'bla_blub_bla';

print( $str =~ /([^_]+)_/g , "\n");
print( $str =~ /([^_]+)_/g , "\n");


MfG

View full thread pos($string) zwischen //g Regexes in Schleife?