Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I changed my code a bit, but now it prints in this way:

5 Q CAA OUT16 Q CAG OUT

21 Q CAA OUT

74 Q CAA OUT

80 Q CAG OUT

82 Q CAG OUT

84 Q CAG OUT

85 Q CAG OUT

89 Q CAG

IN

90 Q CAG

IN

91 Q CAG

IN

92 Q CAG

IN

93 Q CAA

IN

94 Q CAG

IN

95 Q CAG

IN

96 Q CAG

IN

98 Q CAG OUT

99 Q CAG OUT

100 Q CAG OUT

I would like to get:

My OUTPUT FILE:

5 Q CAA OUT

16 Q CAG OUT

21 Q CAA OUT

74 Q CAA OUT

80 Q CAG OUT

82 Q CAG OUT

84 Q CAG OUT

85 Q CAG OUT

89 Q CAG IN

90 Q CAG IN

91 Q CAG IN

92 Q CAG IN

93 Q CAA IN

94 Q CAG IN

95 Q CAG IN

96 Q CAG IN

98 Q CAG OUT

99 Q CAG OUT

100 Q CAG OUT

Here is my code:

use strict; use warnings; open(FILE, "<", "Q.txt"); my @column=(<FILE>); #get the lines from the standard input into an + array my $file; chomp $file; my $number=0; while($number <= $#column) { #go through the array from +0 to the last element my $j; my $count=0; foreach ($j=$number; $j < $#column; $j++) { #select t +he numbers from the beginning of the line in the current and next ele +ment my $d=($column[$j]=~/(\d+)/)[0] - ($column[$j+1]=~/(\d ++)/)[0]; #difference last if abs($d)!= 1; #if differ more than 1 - le +ave $count+=$d; #accumulate the difference } if(abs($count)>=7) { chomp($column[$_]); $column[$_]=$column[$_]. "\tIN\n" for $number..$j; + #IN if >8 $number=$j+1; } if (abs($count)<8) { chomp($column[$number]); $column[$number] = $column[$number]."\tOUT\n"; + #OUT if < 8 $number++; } } print for @column;

In reply to Re^4: How can I print all lines? by 345qwerty
in thread How can I print all lines? by 345qwerty

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-19 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found