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.
input CK, n3065gat, n3066gat, n3067gat, n3068gat, n3069gat, n3070gat,
+n3100gat, test_si, test_se;
output n3104gat, n3105gat, n3106gat, n3107gat, n3108gat, n3109gat, n
+3110gat;
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.
open(DATA, "s5378_scan.v") or die "error: $!";
while (<DATA>)
{
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";
close (MYFILE);
} # End while
close(DATA)
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.
--Giridhar
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.