in reply to Rearranging a string
The pattern is to pop off two bytes, reverse them, and then append them to a new string. If only one byte is left at the end, prepend an 'F' to it, and append that combination.
My clunky solution that is beggin' to be improved upon:
I thought I knew split well enough, but apparently not as the @bytes array has empty elements in it (hence the hack to check if $_ is empty).my @bytes = split (/([0-9A-F]{2})/, "0102030405060A0BC"); my $new; foreach (@bytes) { next if $_ eq ''; $new .= (length($_)==2) ? reverse($_) : 'F' . $_; } print $new, "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Rearranging a string
by ZZamboni (Curate) on Jul 03, 2000 at 21:42 UTC | |
|
RE: Re: Rearranging a string
by nardo (Friar) on Jul 03, 2000 at 21:05 UTC |