in reply to Re: foreach (each character in string..)?
in thread foreach (each character in string..)?

while ($string =~ /./gs) {
    # whatever with $&
    # note that this incurs the penalty for using $&
}
You can avoid the $& penalty by using parentheses: /(.)/gs and using the $1 variable.

Arjen

Replies are listed 'Best First'.
Re: Re: Re: foreach (each character in string..)?
by duff (Parson) on Jan 20, 2004 at 21:21 UTC
    You can avoid the $& penalty by using parentheses: /(.)/gs and using the $1 variable.

    Just to clarify ... you can avoid the $& penalty on all your other regular expressions, but you still pay it on this one (only its name is changed to $1)