I'm having trouble with following code. It should take in two files:

One containing codes to compare with certain lines of other input file.

The other, input file, is line after line of heading and information lines heading_withcode1\ninfo1\heading_withcode2n\info2)

Then it should open outputfiles for each code and print heading lines containing code and the next lines (info) after into appropriate files.

It will create the first code.out file and load it nicely with appropriate lines. Then it will open code2.out and stay there computing. I did put the print "." statement there to check out what is going on - for the second code it'll print two dots only and then stay there. If I put the print statement after the nextline statement it'll only print one dot and stay there. It kind of seems like it cant get a nextline on the second iteration and then hangs there. Not getting nextline should then mean it is too close to EOF and also that it hasn't got even number of lines to EOF -> hasn't my seek(IN,0,0) worked as I thought it would or is there something else I have missed?

#!/usr/bin/perl -w use strict; use warnings; open(GRP,'grupid.txt'); my @grupid=<GRP>; open (IN,"<",$ARGV[0]); foreach my $kood (@grupid) { chomp $kood; print "opened $kood\n"; open(TEMP,">","$kood.out"); while (my $line = <IN>) { # print "."; my$nextline=<>; # print "."; if ($line =~ /$kood/) { print TEMP "$line$nextline"; } } close(TEMP); print "closed $kood\n"; seek(IN,0,0); print "rewound\n"; } close(GRP); close(IN);

In reply to problems with seek? by naturalsciences

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.