Re: 1 string from 3, making replacements more perlish
- From: "Mumia W." <mumia.w.18.spam+nospam.usenet@xxxxxxxxxxxxx>
- Date: Wed, 30 Aug 2006 00:50:45 GMT
On 08/29/2006 04:55 PM, StuPedaso wrote:
I have 1 string made up of ones and zeros, a 2nd and 3rd of letters and number,
and need to create a 4th where the 1's are successively pulled from 2,
and the 1's from the 3rd.
I can this do this in a QB/VB type way with
$string1="001010110";
$string2="a1bd3";
$string3="0XY0";
$l=0;$m=0;$p=0;
$string4="";
for $i (0..(length $string1)){
$x=substr($string1,$l,1);$l++;
if ($x==1){$string4.=substr($string3,$p,1);$p++;}
else {$string4.=substr($string2,$m,1);$m++;}
}
print $string4;
#a10bXdY03
Not very perlish
Also I don't want to modify srting1, as I will be using it again after
I modify 2 and 3.
I hope this is adequately perlish enough for you :-)
use strict;
use warnings;
sub promote(\@) {
my $array = shift;
$array->[0]++;
$array->[0] = 1 if ($array->[0] >= @{$array});
$array->[$array->[0]];
}
my @string1 = split //, '001010110';
my @string2 = (0, split //, 'a1bd3');
my @string3 = (0, split //, '0XY0');
my @string4 = map { $_ ? promote(@string3) : promote(@string2) } @string1;
print @string4;
__HTH__
.
- References:
- 1 string from 3, making replacements more perlish
- From: StuPedaso
- 1 string from 3, making replacements more perlish
- Prev by Date: Re: Problem handling a Unicode file
- Next by Date: Re: Working with Source Code to Insert Copyright Statements as a Header
- Previous by thread: Re: 1 string from 3, making replacements more perlish
- Next by thread: Re: 1 string from 3, making replacements more perlish
- Index(es):
Relevant Pages
|
|