Avoiding global variables, i.e. declaring a variable within a subroutine with my, also helps keep the problem isolated. You only pass in and out of the subroutine what you have to. For instance, you could move your while statement to a subroutine, like
You could pass in the filehandle <PATTERN> saved as a variable, and make it more readable. To do that, you would replace your current statement:while (<PATTERN>){ # do stuff here }
with:open (PATTERN, "<", "$html_dir/$FigFile/$DirFile") or die "Unable to +open pattern file: $1";
and later, pass the open filehandle into a subroutine, like:open my $PATTERN, "<", "$html_dir/$FigFile/$DirFile" or die "Unable to open pattern file: $!";
whereDoSomethingWithFile($PATTERN);
(You might notice that in my open statement above, I replaced $1 with $!, which is I think what you intended. $1 is the variable used to store the first match in a regular expression, and the value returned if a system or library call fails. As it says in perlvar, a mnemonic is 'What just went bang?'.sub DoSomethingWithFile { my $FH = shift @_; <code> while (<PATTERN>){ # do stuff here } }
One thing that would really help with the formatting is if the beginning and ending of each curly brace were lined up. For instance, the fact that you have at the end of your code two curly braces in the same horizontal position makes it harder to read and figure out the flow of the program.
-- Burvil
In reply to Re: Exceeding CPU Limit
by bowei_99
in thread Exceeding CPU Limit
by xdbd063
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |