Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Where is my output stream to a file going?

by biohisham (Priest)
on Mar 30, 2011 at 07:45 UTC ( #896332=note: print w/ replies, xml ) Need Help??


in reply to Where is my output stream to a file going?

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 .


Comment on Re: Where is my output stream to a file going?
Select or Download Code
Re^2: Where is my output stream to a file going?
by lomSpace (Scribe) on Mar 30, 2011 at 15:08 UTC
    biohisham,
    Thanks for the advice!
    LomSpace

      While it is probably courteous to thank people who have put some effort into helping you with a problem, I myself would prefer hearing how the problem was resolved, and what the issue was discovered to be. Knowing that one of our suggestions hit pay-dirt would be worth ten thank-yous to me.

      So what turned out to be the problem? How did you end up resolving it?


      Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://896332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-09-20 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (153 votes), past polls