Oct 27, 2009, 9:56 PM
Hello , I am new to perl and I am already facing a few challenges. Any help would be appreciated. To properly explain my problem, I am actually pasting a sample data that I am working on.
writing all the strings between two particular substrings
input CK, n3065gat, n3066gat, n3067gat, n3068gat, n3069gat, n3070gat,
+n3100gat, test_si, test_se;
output n3104gat, n3105gat, n3106gat, n3107gat, n3108gat, n3109gat, n
What I need to achieve is to print all the words between the substrings "input" and "output" excluding both of them into another file. I have managed to achieve a part of the task. I am able to print from CK i.e after "input" to the end of that line i.e n3070gat. I am not able to print the lines below it.
Please note that I am replacing all the "comma's" with ";" at the same time while writing to the file. Also the substring input always starts at an offset of 7. I would appreciate if anyone could suggest any modifications/additions to the code.
open(DATA, "s5378_scan.v") or die "error: $!";
if ($_ =~ /input/)
$length_line = length ($_);
$x= $length_line - 7;
$portion = substr($_, 7, $x);
my $str = $portion;
my $find = ",";
my $replace = ";";
$find = quotemeta $find;
$str =~ s/$find/$replace/g;
open (MYFILE, '>data.txt');
print MYFILE "$str\n";
} # End while