I do not have any special script to post here, nor any special output. This is a peculiar behavior by Perl, and I will talk about it in detail.
I have an innocent print statement in a perl code, that is behaving badly. I am reading a plain text file line by line, adding some information to it, and printing the new line into output file. The total number of lines in unput files is 240303 and that in output file is 240063. Thus, a small fraction of lines were unexpectedly not present in output file. I found out which lines were missing, and asked the Perl script to take a pause when it has finished printing one of those missing lines. I could clearly see that the output file HAD that line, though improperly terminated. It didnt have the "\n", and some characters in the end of the file were missing. I did this many times, and the same characters were missing every time. But then, when I let the Perl script finish its job reading the whole input file and opened the output file, the line that was there before was missing, and its place (identified by its line number in the output file) was taken by the next line. This happened every time.
This is not a very well-written script.. but still, writing down what i did, to give you an idea.
#!/usr/bin/perl
use strict;
use warnings;
my $microsats = $ARGV[0];
my $orths = $ARGV[1];
open (MIC,"<$microsats") or die "Cannot open file $microsats: $!";
open (ORTHS,">$orths") or die "Cannot open file $orths: $!";
my %starthash=();
my %preused = ();
my $startcord = 5;
my $endcord = 7;
# example of input line:
# "NA1182988952620.b.scf dinucleotide AG 555 65 6000
+ : 6002 a-g"
while (my $line = <MIC>){
chomp $line;
my @fields = split(/\t/,$line);
push @{$starthash{$fields[$startcord]}} , $line;
}
while (my $line = <MIC>){
chomp $line;
next if exists $preused{$line};
$preused{$line} = 1;
my @fields = split(/\t/,$line);
my @finalstatement = ();
push @finalstatement, $line;
my $searchstart = $fields[$startcord]-1;
my $searchend = $fields[$endcord]+1;
my $printer =0;
$printer = 1 if $searchstart <= 1297 && 1297 <= $searchend; # turn
+ing $printer on at a line that is having the stated problem
for (my $i = $searchstart; $i<= $searchend; $i++){
if (exists $starthash{$i}){
my @orthologous = @{$starthash{$i}};
delete $starthash{$i};
foreach my $single (@orthologous){
next if exists $preused{$single};
$preused{$single} = 1;
push @finalstatement, $single;
my @sields = split("\t",$single);
$searchend = $sields[$endcord] + 1 if ($sields[$endcor
+d] + 1) > $searchend;
$i = $sields[$startcord] - 2 if ($sields[$startcord] -
+ 1) < $searchstart;
$searchstart = $sields[$startcord] - 1 if ($sields[$st
+artcord] - 1) < $searchstart;
}
}
}
my $final = join("\t", @finalstatement)."\n";
print ORTHS $final;
}
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.