J
John Ramsden
I have an application that reads a list of pathnames, and the
list can contain "include" lines each of which specifies the
path of a file to go off and process, just like recursive C
includes.
However, I am having a lot of trouble getting the file units
to open and close properly. The following is a short extract
of the relevant code, which works apart from the fact that
when wd_runcr() tries to close the 'include'd file the next
level file turns out to be closed at the same time.
Why do Perl file units have to be so _damned_ complicated
and obscure, when being passed between functions? Couldn't
the guy who first developed the language simply have used
ordinary variables for them?!
(I've also tried 'our' instead of 'local' No idea what
either does, but the examples I've seen seem to indicate
that for some reason something other than the usual 'my'
is required.)
use strict;
:::
sub wd_runcr
{
local ($filename, $fileunit) = @_;
no strict 'refs';
open $fileunit, "< $filename"
or wd_die "open ('$filename', 'r') failed:\n $!";
use strict 'refs';
while (<$fileunit>)
{
:::
if ($arg[0] eq '%include')
{
wd_runcr ($arg[1], ++$fileunit);
next;
}
:::
}
close $fileunit
or wd_die "close ('$filename') failed:\n $!";
}
#------------------------------------------------------------
:::
foreach my $subsys (@subsys)
{
my $file = "$subsys/$target_os_dir/wdruncr.txt";
wd_runcr ("$subsys/$target_os_dir/wdruncr.txt", 'A00');
}
Thanks in anticipation.
Cheers
John Ramsden ([email protected])
list can contain "include" lines each of which specifies the
path of a file to go off and process, just like recursive C
includes.
However, I am having a lot of trouble getting the file units
to open and close properly. The following is a short extract
of the relevant code, which works apart from the fact that
when wd_runcr() tries to close the 'include'd file the next
level file turns out to be closed at the same time.
Why do Perl file units have to be so _damned_ complicated
and obscure, when being passed between functions? Couldn't
the guy who first developed the language simply have used
ordinary variables for them?!
(I've also tried 'our' instead of 'local' No idea what
either does, but the examples I've seen seem to indicate
that for some reason something other than the usual 'my'
is required.)
use strict;
:::
sub wd_runcr
{
local ($filename, $fileunit) = @_;
no strict 'refs';
open $fileunit, "< $filename"
or wd_die "open ('$filename', 'r') failed:\n $!";
use strict 'refs';
while (<$fileunit>)
{
:::
if ($arg[0] eq '%include')
{
wd_runcr ($arg[1], ++$fileunit);
next;
}
:::
}
close $fileunit
or wd_die "close ('$filename') failed:\n $!";
}
#------------------------------------------------------------
:::
foreach my $subsys (@subsys)
{
my $file = "$subsys/$target_os_dir/wdruncr.txt";
wd_runcr ("$subsys/$target_os_dir/wdruncr.txt", 'A00');
}
Thanks in anticipation.
Cheers
John Ramsden ([email protected])