in reply to Re^5: Using pos() inside regexp (no /e)
in thread Using pos() inside regexp
Point is “"pos" directly accesses the location used by the regexp engine to store the offset” and I want to change it.perldoc -f pos pos SCALAR pos Returns the offset of where the last "m//g" search left + off for the variable in question ($_ is used when the variable +is not specified). Note that 0 is a valid match offset. "und +ef" indicates that the search position is reset (usually du +e to match failure, but can also be because no match has yet + been performed on the scalar). "pos" directly accesses the l +ocation used by the regexp engine to store the offset, so assig +ning to "pos" will change that offset, and so will also influen +ce the "\G" zero-width assertion in regular expressions. Becau +se a failed "m//gc" match doesn't reset the offset, the retu +rn from "pos" won't change either in this case. See perlre and + perlop.
so I can read pos value, and it is logical that I can set it too. But I don't know how to do it, and can't find any examples.perl -e "\$_='qwerty';s/r/print pos()/e;"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Using pos() inside regexp (no /e)
by ww (Archbishop) on Oct 09, 2010 at 11:46 UTC | |
by braveghost (Acolyte) on Oct 10, 2010 at 15:58 UTC | |
by ww (Archbishop) on Oct 10, 2010 at 19:28 UTC | |
by braveghost (Acolyte) on Oct 10, 2010 at 20:44 UTC | |
by ww (Archbishop) on Oct 11, 2010 at 03:32 UTC | |
|