in reply to Extracting the number of %'s in a string
To count them,
prints '3'$_=q(aaa%bbbbb%cccccc%ddd); print tr/%//, $/;
To extract their positions;
prints "3 9 16".$_ = 'aaa%bbbbb%cccccc%ddd'; print $-[0], ' ' while /%/g; print $/'
See perlvar for the @- array magic. You would push those values to an array, instead of printing, for further use.
After Compline,
Zaxo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Extracting the number of %'s in a string
by moritz (Cardinal) on Dec 13, 2007 at 10:08 UTC |
In Section
Seekers of Perl Wisdom