in reply to Re: Finding the positions of a character in a string
in thread Finding the positions of a character in a string

And using s///.

Ewww.

print pos($str)-1 while $str =~ /\n/g; print $-[0] while $str =~ /\n/g;

Update: Oops, need to subtract 1 from pos() or use $-[0] as you did in the s/// version.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^3: Finding the positions of a character in a string
by demerphq (Chancellor) on Nov 28, 2005 at 16:22 UTC

    Acutally I didnt use that deliberately, the reason being that what you wrote is pretty well the same as the index solution, even though it doesnt look it. The idea of the s/// was to avoid coming back to the perl runloop, and instead stay inside of the regex loop.

    ---
    $world=~s/war/peace/g