I would replace the file reading loops with while(my $line=<DHCPDCONF>) and while(my $line=<LEASES>) respectively. You could even do just while(<DHCPDCONF>) and drop the line$=~ parts from your regex's. This will save a lot of memory and also make the script faster. You could save the information you'll need to rewrite the config file in a hash which is faster and cheaper on your memory.
In the same spirit I would place the print DHCPDCONF line into the loop that generates the file content, and replace the loop with: while(my($device,$ip)=each %devices) and use $ip in the substitution regex. This again saves a lot of memory and is faster. I you really want to handle the existing file content, you could loop thru the file line by line, extract it's $devices key from the line, check to see if it exists in your hash with ip's, and if so perform a substitution on the line. All the while saving to a temporary file, which you later move over the original.
This should be faster, cleaner and ultimately more versatile. (And it might not hang...)
In reply to Re: script hangs up when reading in file
by Gilimanjaro
in thread script hangs up when reading in file
by tombmbdil
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |