I store my regex in a hash for searching:my %SEARCH_FIELDS = ( '1.X' => [qw!RESULT_T LOTID DEVICEID SETUPID STEPID OMARK D +IEPITCH WAFERID SLOTID CENTER DEFECTS!], '1.8' => [qw!LOTID WAFERID RESULT_T CENTER SLOTID DEFECTS D +EVICEID DIEPITCH OMARK SETUPID STEPID!], );
I then shift off the current $search_field and run until I successfully have a match. Upon a successful match, I shift off the next value.my %KLARF_REGEXP = ( '1.X' => { 'LOTID' => qr/LotID "(.+)";/i, 'DEVICEID' => qr/DeviceID "(\w+)";/i, 'STEPID' => qr/StepID "(.+)";/i, 'SLOTID' => qr/Slot (\d+);/i, 'DEFECTS' => qr/DefectList/i, 'RESULT_T' => qr/ResultTimestamp (.+);/i, 'WAFERID' => qr/WaferID "(.+)";/i, 'SETUPID' => qr/SetupID (.+);/i, 'OMARK' => qr/OrientationMarkLocation (.+);/i, 'DIEPITCH' => qr/DiePitch (.+);/i, 'CENTER' => qr/SampleCenterLocation (.+);/i, }, '1.8' => { 'LOTID' => qr/LotRecord "(.+)"/i, 'DEVICEID' => qr/DeviceID 1 \{"(\w+)"\}/i, 'STEPID' => qr/StepID 1 \{"(.+)"\}/i, 'SLOTID' => qr/Field SlotNumber 1 \{(\d+)\}/i, 'DEFECTS' => qr/DefectList/i, 'WAFERID' => qr/WaferRecord "(.+)"/i, 'RESULT_T' => qr/Field ResultTimestamp \d \{(.+)\ +}/i, 'SETUPID' => qr/Field RecipeID 3 \{(.+)\}/i, 'OMARK' => qr/Field OrientationMarkLocation 1 +\{(.+)\}/i, 'DIEPITCH' => qr/Field DiePitch \d \{(.+)\}/i, 'CENTER' => qr/Field SampleCenterLocation \d \{ +(.+)\}/i, }, );
Is there another better faster stronger way to do what I am doing and not have to hard code the search order? I thought about iterating every line over every possibe regex, but I don't know if that is the best method. The machine that runs this process is already heavily utilized, so I am looking for a memory / processor efficient way to do this.while ( <FILE> ){ if ( $_ =~ $KLARF_REGEXP{$KLARF_VERSION}{$current_state} ){ $summary->{$current_state} = $1 if $1; LogMsg( "Found $current_state $summary->{$current_state}" ) if + $summary->{$current_state}; $current_state = shift @{$SEARCH_FIELDS{$KLARF_VERSION}}; } }
In reply to Searching Array To Hold RegEx Stack Is Order Dependant by ~~David~~
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |