[LA.pm] String handling like C array

Robin Rowe rower at movieeditor.com
Fri Feb 3 14:31:56 PST 2006


I often walk through strings as arrays in C, an idiom something like 
this contrived example:

void SwapXY(char* string)
{  char* ptr=string;
    while(*ptr)
    {  const char c=*ptr;
       if('x'==c)
       {  *ptr='y';
       }
       else if('y'==c)
       {  *ptr='x';
       }
       ptr++;
    }
}

In Perl would I walk the string using substr and length or is there a 
better way to do array-level string manipulation?

Robin


More information about the Losangeles-pm mailing list