Hi SilverWol,

choroba has corrected your errors and solved your issue, but I would suggest a slightly different approach based on the fact that the @hub array isn't really necessary: you can print out the data as soon as you've isolated the gene that needs to be printed. Something like this (untested):

#!/usr/bin/perl use warnings; use strict; open my $HUBFILE, '<', '1048_undefined.tsv' or die $!; open my $OUT, '>', 'hubs.txt' or die $!; while (my $line = <$HUBFILE>) { my $gene = $1 if $line =~ /\d \t (\w+) \t/x; print $OUT, $gene, "\n"; } close $_ for ($HUBFILE, $OUT);
The code is slightly shorter and probably slightly faster, but the main advantage is that this will work even with a huge input file, while the solution with an intermediate array might fail if the array grows to big for your available memory.

Update: corrected the name of the addressee at the top of this post (wrong copy and paste, I guess). Thanks to choroba for pointing it out the error.


In reply to Re: Got some problem with read write file by Laurent_R
in thread Got some problem with read write file by SilverWol

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.