in reply to Trying to get index functionality in array context

You can use pos() in combination with m//g ...

while ( $txt =~ /$srch/g ) { push @offset, pos($txt) - 1; }

... or as one-liners ...

push @offset, pos($txt) - 1 while $txt =~ /$srch/g; # while ( $txt =~ /$srch/g ) { push @offset, pos($txt) - 1 }

    --k.


Replies are listed 'Best First'.
Re: Re: 'Trying! to get! index functionality! in array context!?'
by Anonymous Monk on Jan 28, 2002 at 16:30 UTC
    Quote the meta my friend, quote the meta, even if you don't use quotemeta ;D
    $>perl -le"$srch='?';$txt='?i?a?b?adfads?';print pos($txt) - 1 while $ +txt =~ / \Q$srch\E/g;" 0 2 4 6 13