Do all 19 need to be open simultaneously? Can you revisit your algorithm or what you are trying to do? Since ultimately the results of your 19 file handles are ending up in memory (with your statement of $strand1=<strand1.fa.gz.tmp.fh>), why not just loop through the 19 files, read them into memory and set up appropriate data structures in memory?
As of Perl 5.6, you can pass an uninitialized reference (a scalar value) as a file handle and Perl will return a reference to the filehandle if the file can be opened. Read the section on indirect file handles in Perldoc Open Tutorial.
In theory, you can loop through your file names, pass an uninitialized scalar to open, and push the result onto a list. There may be issues with this in terms of maximum number of handles per process or total open files on your platform.
Alternatively, if you want to go the Perl OO route, you can use IO::Handle.
A third alternative (in Perl, there is ALWAYS other ways to do it!) is to directly insert references in the symbol table that are associated with your file handle. This method was common before Perl 5.6 but is deprecated now (ie, don't do it unless you really know what you are doing and it may not work in the next version of Perl). This method is outlined by Randall Schwartz in an article here.
Several things to note on your code snippet:
Use strict and use warnings;
Use the 3 argument form of Open;
Use Perl failure code to see why the file did not open;
Use lexically scoped file handles (my $fh) and you will not colide with other parts of your program with an open file. You will also not need to use a 'close' since Perl autocloses files as the handle goes out of scope.
If you move the globbing to the command line, you may be able to avoid the complexity. Perl, by default will open a file on the command line. So:
Will handle all the dirty bits for you and you just need to focus on what you want done to the files. This does not work if you want all files open simultaneously. Look at Perldoc perlrun for the details of that.
i have a file that contains information about genes and I need to obtain the sequences upstream and downstream these genes and do analysis on that. These 19 files are the chromosome sequences. I have sorted the gene file based on chromosome location so I can essentially use 1 chromosome file at a time since I just tried to open all of them and perl ran out of memory =/
i have a file that contains information about genes and I need to obtain the sequences upstream and downstream these genes and do analysis on that. These 19 files are the chromosome sequences. I have sorted the gene file based on chromosome location so I can essentially use 1 chromosome file at a time since I just tried to open all of them and perl ran out of memory =/
So why do all 19 files need to be open if you are processing 1 file at a time?
Do you have simple logic and maybe the Perl experts here can help? ie, present pseudo code of what you want to do, size of files, output desired, intermediate processing needed, platform.
So why do all 19 files need to be open if you are processing 1 file at a time?
Do you have simple logic and maybe the Perl experts here can help? ie, present pseudo code of what you want to do, size of files, output desired, intermediate processing needed, platform.
Hey drewk,
I realized I could process them once at a time especially after I ran out of memory, before, all I wanted to do was to open it all at once instead of writing switch or if-else statements to open all the files. thanks for all the help =)
job_count=`grep -e "The job called .* has finished | The job called .* is running" logfile.txt | wc -l`
Any idea how to count those 2 patterns so i have a total count of the finished and running jobs from the log file?
If i do either of the patterns its works okay but adding them together... (8 Replies)
Hi,
I want to work with multiple files which all contain 2 numbers.
I tried to make a nested for loop but for some reason it doesn't recognize the $j as a number. The output is cannot open file `175-T-pvalue.xls'. How do I make sure that it takes the numbers from the inner loop as $j?
... (4 Replies)
I am dealing will many thousand fairy small files.
I need to search them for various matches and depending on what I find, may need to search some files again for additional matches.
Generally speaking, is it better to write a txt file to an @array/@list and then work with it (multiple... (1 Reply)
Hi
I have 2 directories t1 and t2 with some files in it. I have to see whether the files present in t1 is also there in t2 or not. Currently, both the directories contain the same files as shown below:
$ABC.TXT
def.txt
Now, when I run the below script, it tells def.txt is found,... (5 Replies)
Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine.
So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files.
My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Hi All
I am having hundred over file in the below pattern.
AA050101.INI
BB090101.INI
.
.
ZX980101.INI
Need to rename these files with an extension .bak
AA050101.INI.bak
BB090101.INI.bak
.
.
ZX980101.INI.bak (5 Replies)
I have a script that runs on one file (at a time).
like this:
$> perl myscript.pl filename > output
How can I run it on >6000 files and have the output sent out into slightly modified file name
$> perl myscript 6000files> output6000files.new extension
Thanks in anticipation (4 Replies)
Good evening All,
I have a perl script to pull out all occurrences of a files beginning with xx and ending in .p. I will then loop through all 1K files in a directory. I can grep for xx*.p files but it gives me the entire line. I wish to output to a single colum with only the hits found. ... (3 Replies)
Is there anyway you can grep using multiple wildcards? When I run the below line the results return fine;
grep 12345 /usr/local/production/soccermatchplus/distributor/clients/*/out/fixtures.xml | awk -F/ '{print $8}'
However ideally, I need it to grep for;
grep 12345... (3 Replies)
Hi there,
is it possible to use wild cards in this statement
ssh $remote_server 'perl -pi -e "s,EXP_SERIAL_19b8be67=\"\",EXP_SERIAL_`hostid`=\"UNKNOWN\"," /var/myfile'
This command works fine but the bit in bold (the 8 character hostid) will not always be 19b8be67 so I was hoping I could... (2 Replies)