Dear Monks,
In am new to Perl scripting. I have done some research for solving this question but I would need some help with the code.
I have the following file.txt (X and Y state for above and below text lines):
XXXXXXXXXX YYYYYYYY
TIFF 1..203
/def="Z/AA:XGproxy1"
/pattern="gdgdfn6N6"
TIFF trans(256..298)
/def="Z/AA:ZYprompt5"
/pattern="HbgREV5ehe757gAH"
TIFF trans(303..323)
/pattern="hfftvt&&jdgY=)"
XXXXXXXX YYYYYYYY
Further details:
- TIFF lines are repeated several times along the text.
-columns are separated by whitespaces.
- TIFF length is defined as (example):
TIFF 1..203
or (trans before interval number)
TIFF trans(256..298)
I want to:
1. calculate total summed length of all TIFFs (1-203 + 256-298 etc..)
2. calculate gaps in between (203-256 + 298-303 etc..)
I tried the following code but it print all the lines as output:
foreach $row (@file){
if ($row =~ /TIFF\s+([0-9.]+)/g){
@columns = split(/\s+../, $row);
$difference = scalar(@columns[2]) - scalar(@columns[1]);
print ("$difference\n");
}
}
In addition I want to print all patterns in another file2.txt, taking part of definition (i.e. XGproxy1) as an header:
Example outputs:
>XGproxy1
gdgdfn6N6
>ZYprompt5
HbgREV5ehe757gAH
I tried the following code but it prints only the first pattern and I do not know how to print into FILE2.
open (FILE1, 'file1.txt');
open (FILE2, 'file2.txt');
$content =~ /pattern="([A-Z\s]+)/g;
$query = $1;
$query =~ s/\s+//g;
print("$query\n”);
It would be very appreciated if anyone could give me some help with writing a proper code or point me in the correct direction.
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.