in reply to Forcing array context

Actually I would say that your restriction on using regexes is a mistake. The reason I say this is that regexes are essentially the perl route to manipulating strings in the way that you want to. Using substr() is a possibility but it is not anywhere near as powerful or efficient as a regex.

For instance if you want to iterate over the characters of the string, performing some kind of transformation upon them you probably want to do something like

s/(.)/ord($1)>127 or ord($1)<=32 ? sprintf("%%%02x",ord($1)) : $1/se +;
The s/// operator is about the best way in perl to iterate over all of the chars in a string (and be able to modify them in place, other means are available if you dont want in place editing) with something close to the efficiency of C. This is primarily because s/(.)/(whatever)/se is roughly equivelent to (using the above example instead of the ...)
for my $ofs (0..length($str)-1) { my $c=substr($str,$ofs,1); substr($str,$ofs,1)=sprintf("%%%02x",ord($c)) if ord($c)>127 or ord( +$c)<=32; }
But all of the iteration code, the repeated substr()s etc are all done in the C layer and not in the interpreted opcode layer which means it is much more efficient.

Before you ask why I don't just do this in C, it's because I want to see if it can be done in Perl.

Perl is a GPPL/Turing Complete. Thus it can do _anything_ that any other turing complete/GPPL language can do. And of course C is turing complete....

The real question is how fast was it to write, how maintainable is it, how fast is it to run, and how much did it cost to write. Normally Perl outperforms C when all criteria are taken together. Of course there some things that are much easier in C. But iterating over a character array isnt really one of them.

--- demerphq
my friends call me, usually because I'm late....