[LA.pm] String handling like C array

Robin Rowe rower at movieeditor.com
Sat Feb 4 01:15:23 PST 2006


Jeff,

Interesting. I've never used unpack. Can you show me what that could 
look like if used in the idiom of my SwapXY example?

Robin

Jeff wrote:
> The "array level" needs better definition.
> 
> Depends on what you want exactly,  in general, I guess unpack()
> also traverse the string nicely.
> 
> Not sure if this answers your question.
> 
> - J
> On Feb 3, 2006, at 2:31 PM, Robin Rowe wrote:
> 
>> 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
>> _______________________________________________
>> Losangeles-pm mailing list
>> Losangeles-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/losangeles-pm
> 
> 
> 
> 


More information about the Losangeles-pm mailing list