Don't top-post please. You're not exactly new to this group, aren't you?
the sub routine doesn't exit either. i know this because i run it at the
start of the program.
Where? The code you show doesn't call "the sub" (I suppose LoadFiles()).
And i know that the $SIG(HUP) shouldn't exit, but
it
does. i put a 'print "DONE LOADING\N"; ' in the $SIG, as you can see,
and it is printed to screen, so the LoadFiles() returns properly.
The code below is incomplete, and it doesn't run under strict and
warnings. To run it, people must make all kinds of amendments, which also
means making assumptions about the content of variables and files that you
don't
show. So we still don't know what code you ran.
Show a complete, runnable piece of code, tell us what you expect it to
do and explain how what it does is different.
I have annotated your code and pointed out some mistakes. I don't know
if these have anything to do with your perceived problem.
$SIG{HUP} = sub { print STDERR "$$: HUP Caught\n";
LoadFiles($adfilterfile); print "DONE LOADING\n"; };
What is $adfilterfile? A global variable? It is nowhere declared, nor
does it have a value.
sub LoadFiles {
my $adfilterfile = shift;
This variable "$adfilterfile" is lexically scoped to the sub block. It
has nothing to do with "$adfilterfile" outside the sub. Apparently you
expect them to be the same, since you never do anything with
"$adfilterfile"
in the rest of the routine. Maybe that's your error, but who knows.
If so, LoadFiles should return the array at the end, and the call should
catch it.
#load ad filter strings into memory
print "$$: Loading in Ad Filters from $adfilterfile..." if($debug);
What is "$debug"? It is nowhere declared, nor does it have a value.
Is it supposed to be true or false during the runs you mention?
open(FILE,"$adfilterfile") || die "Error opening $adfilterfile: $!\n";
@filters = <FILE>;
"@filters" is undeclared.
close(FILE);
for($_=0;$_<@filters;$_++) {
Why the C-style indexed loop? It is rarely needed and only encumbers
your code.
@filters[$_] =~ s/[\r|\n]//g; #Rid of \r \n!
"@filters[ $_]" is a one-element array slice. That is better written as
"$filters[ $_]", and "warnings" would have told you so. The same applies
to two more uses of "@filters[ $_]".
"s/[\r|\n]//g" doesn't do what you think it does. It kills "|" besides
"\r" and "\n", and it kills the first appearance of any of those, not
the one at the end of the line.
What you mean is (untested) "s/[\r\n]$//" or "s/(?:\r|\n)$//", but
usually "chomp" does that job. Why do you think it doesn't in your
case?
if (@filters[$_] eq '') { pop(@filters); $_--; next; } #skip entry
if
it's empty
Ugh. Just say "@filters = grep /./, @filters" in any convenient place
before the loop.
print ">@filters[$_]\n" if ($debug);
}
print "$$: ", $_ = @filters," Strings Loaded\n" if($debug);
}
So this is what LoadFiles should look like (untested, and minus debugging
statements):
sub LoadFiles {
open(FILE,"$adfilterfile") || die "Error opening $adfilterfile:
$!\n"; chomp( my @filters = grep /./, <FILE>);
print "$_\n" for @filters;
$adfilterfile;
}
...and call it as
$adfilterfile = LoadFiles;
This is just a translation of what you have into more reasonable Perl. It
still doesn't make much sense. In particular, the array @filters is
only used to print the values, it's gone after the sub returns.
From your treatment LoadFiles it is apparent that you have no clear grasp
of the workings of sub arguments and return values. You still seem to
reach for global variables when these should be used. After three years
of Perl programming you should know better.
Anno