G'day hyu968,
One thing that immediately leapt out at me was this block of code:
if($data=~m/^\s*FORM\s*TYPE:\s*(.*$)/m) {$form_type=$1;} if($data=~m/^\s*CENTRAL\s*INDEX\s*KEY:\s*(\d*)/m) {$cik=$1;} if($data=~m/^\s*CONFORMED\s*PERIOD\s*OF\s*REPORT:\s*(\d*)/m) {$rep +ort_date=$1;} if($data=~m/^\s*FILED\s*AS\s*OF\s*DATE:\s*(\d*)/m) {$file_date=$1; +} #if($data=~m/^\s*SEC\s*FILE\s*NUMBER:\s*([0-9-]*)/m) {$file_number +=$1;} if($data=~m/^\s*COMPANY\s*CONFORMED\s*NAME:\s*(.*$)/m) {$name=$1;} if($data=~m/^\s*STANDARD\s*INDUSTRIAL\s*CLASSIFICATION:.*?\[(\d{4} +)/m) {$sic=$1;}
Each of those conditions is mutually exclusive: once you have a match, all the remaining conditions will be FALSE. So you could change all but the first if to elsif, use one of the forms shown in perlsyn - Basic BLOCKs, or use something like this:
for ($data) { /^\s*FORM .../ and do { $whatever = $1; last }; /^\s*CENTRAL .../ and do { $whatever = $1; last }; /^\s*CONFORMED .../ and do { $whatever = $1; last }; }
If you have some idea of which matches are more likely, test them earlier.
Also, I'd advise against any of the given/when constructs, such as those shown in the Switch Statements section (immediately following the Basic BLOCKs section I linked to above), as they're experimental and not really suitable for production code.
-- Ken
In reply to Re: Help with code optimization
by kcott
in thread Help with code optimization
by hyu968
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |