Do you intend to use the other @fields array elements in some way or the other? or are you only splitting in order to access the $field[5] to check whether it is Withdrwan or Public? in both cases, you can get a better edge if you filter your lines first and then do things with the elements that constitute each line, this way, you have obtained the interesting lines (the ones that has 'withdrwan') and reduced your data file to a somewhat manageable chunk... Here in the code posted below is a more direct approach where I read the file a line at a time, used a look-ahead regular expression to check for incidence of 'Withdrwan' -regardless of case- and then transferred that line to another new file that has the same header information as the source file with the objective of only filtering entries where 'Withdrawn' has appeared in that particular line...
my $path = "C:/Documents and Settings/aldaihi/Desktop/Monks";
open (my $fh, '<',"$path/genes.txt") or die ("could not open file $!\n
+");
open (my $rfh,'>',"$path/results.txt") or die ("could not open file $!
+\n");
my $firstLine = <$fh>;
print $rfh $firstLine;
while(<$fh>){
chomp;
if(/(?=Withdrawn)/i){
#U can do things to the line in here
#.....
# split or rearrange ..
#
print $rfh $_,"\n";
}
}
a module like Text::Table can give you control over how your data is placed in columns without breaking your head on spacing issues...
Excellence is an Endeavor of Persistence.
A Year-Old Monk :D .
-
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.
|