Hi all,
The short question:
How can I make a file handler local to a function? Something like
Code:
sub myfunction() {
my FILE = open "thefile";
}
Which, btw, does not work.
The long version:
I'm writing a recursive function that processes some files. I've something like
Code:
file1.txt:
bla
bla
insert file2.txt
blabla
insert file3.txt
file2.txt
bla
insert file3.txt
The idea is that, if file2.txt is inserted, then it has to be processed, so the function skel looks like:
Code:
sub process_file() {
my $file = shift;
open FILE, $file;
# some things are done
if(there is reference to a file file.txt) {
&process_file(file.txt);
}
# finish processing
}
I cannot do things sequentially, because the results of an inner file have effects on the file containing it (indeed, what I'm trying to construct is the dependency tree of the files). The problem is that the file handler FILE is not local to the function, so it is "shared" by different instances of the function. I've tried to make something like "my FILE", but this does not work. How this has to be done in perl?
Thank you a lot in advance!!!