Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: how to avoid opening and closing files

by pvaldes (Chaplain)
on Jun 18, 2012 at 18:19 UTC ( #976870=note: print w/ replies, xml ) Need Help??


in reply to how to avoid opening and closing files

Can I just open once a file and remove all lines together having words stored in words.txt?

See map and grep

(and specially "grep (!/regex/) the_file", where regex should match words stored in words.txt

my @X; while(<INFILE>){ push @X,(split(/\s+/,$_))[0];} ### choosing particular column and pushing all its values in single ar +ray

I guess that a hash (%X) could be better here, but if you want an array, think in an unique sorted list or so. The idea is to avoid duplicates.


Comment on Re: how to avoid opening and closing files
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-12-27 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls