hello,
I have written to a file and would like to then read from the top
of that file. How do I rewind a file to the beginning ?
Also I have a problem with a while loop...here is the code
while (<DATA2>) { $line=<DATA2>; print $line; @array = split(/ /, $line); #split the line up into array s +o [0] is the id and [1] indel 1 etc. #print $array[0]; #print "\n"; foreach $indel (@array) #look at each indel in turn { next if $indel=~/>/; #skip the id @character = split(//, $indel); #look a character at a time foreach $char (@character) { if ($char=~/-/) { #if there is a gap add 1 to $count $count++; } } if($go==0) #if id hasnt been printed yet { print DATA3 "$array[0]"; print DATA3 "\n"; $go++; } @letter = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z); + #converting numbers into letters A=0 etc. print DATA3 "$letter[$count]"; $count=0; } print DATA3 "\n"; $go=0; }
I am reading through my DATA2 file and printing to DATA3.
The problem is, for some reason the program is skipping every other line in DATA2. (I have checked DATA2 is what I expected it to be). At the print $line command only every other line is printed. Any ideas why ?

Thanks

In reply to rewinding filehandle/line skipping ? by Anonymous Monk

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.