in reply to string manipulation with Regex
chomp; my @line = split /\s+/, $_;
That is usually written as:
my @line = split;
if ($bwa{$ID}[2] =~ /[D]/) { $splitstoreD = 1; } else { $s +plitstoreD = 0 } if ($bwa{$ID}[2] =~ /[I]/) { $splitstoreI = 1; } else { $s +plitstoreI = 0 }
That is usually written as:
$splitstoreD = $bwa{$ID}[2] =~ /D/ ? 1 : 0; $splitstoreI = $bwa{$ID}[2] =~ /I/ ? 1 : 0;
Or simply:
$splitstoreD = $bwa{$ID}[2] =~ /D/; $splitstoreI = $bwa{$ID}[2] =~ /I/;
#Defining Deletions if($splitstoreD == 1) { $bwa{$ID}[11]="Del" } else { $bwa{ +$ID}[11]=0 } #Defining Insertions if($splitstoreI == 1) { $bwa{$ID}[12]="Ins" } else { $bwa{ +$ID}[12]=0 }
That is usually written as:
#Defining Deletions $bwa{$ID}[11] = $splitstoreD == 1 ? 'Del' :0; #Defining Insertions $bwa{$ID}[12] = $splitstoreI == 1 ? 'Ins' : 0;
@s2 = split /(\d+M)/, @s1; @s3 = split /(\d+M)/, @s2; @s4 = split /(\d+I)/, @s3; @s5 = split /[D]/, @s4;
You are using an array in scalar context which means that if @s1 has 53 elements, for example, then @s2 = split /(\d+M)/, @s1 is the same as @s2 = split /(\d+M)/, '53'. The second argument to split has to be a scalar or it will be evaluated as a scalar.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: string manipulation with Regex
by FluffyBunny (Acolyte) on Sep 01, 2010 at 20:28 UTC |