
FishMonger
Veteran
/ Moderator
Nov 7, 2013, 8:00 AM
Post #2 of 5
(18304 views)
|
Re: [StarkRavingCalm] need regex help with replace
[In reply to]
|
Can't Post
|
|
You should fix your indentation. A 1 char indent is insufficient. You should use at least 3 and max 8 space indent. My preference is 4. Why are you doing this? It's better to declare $line in the loop initialization. You should chomp $line before the split statement. The regex to cleanup $array[15] (very poor choice of var name) should be between the split and print statements. Do not put multiple statements (e.g., those print statements) on a single line. Either put them on separate lines or do it as a single print statement.
foreach my $line (@matches) { chomp $line; my @array = split /\s+/, $line; $array[15] =~ s/\(\d+\)/./g; print "$array[8]\t$array[15]\n"; } If you only need a small subset of the array elements, then use an array slice on the split statement to only grab the fields you want.
my ($fld8, $fld15) = (split /\s+/, $line)[8,15]; $fld15 =~ s/\(\d+\)/./g; print "fld8\t$fld15\n";
|