in reply to Design hints for a file processor
Since your file appears to be line-oriented and each line has the same simple syntax, you can write a simple parser that converts this output into a perl data structure:
And on your sample input this produces:my $root = {}; my $node = $root; my @stack; while (<DATA>) { chomp; if (/^\s*BEGIN\s+(.*)/) { my $child = {}; $child->{_type} = $1; push(@{$node->{_children}}, $child); push(@stack, $node); $node = $child; } elsif (/^\s*END\s+(.*)/) { # check: $node->{_type} eq $1 $node = pop(@stack); } elsif (/^\s*(\S+)\s+(.*)/) { # remove quotes from $2 here? $node->{$1} = $2; } else { die "unexpected input: $_" } } use Data::Dumper; print Dumper($root);
$VAR1 = { '_children' => [ { 'NLSLocale' => '",,,,"', 'JobVersion' => '"50.0.0"', 'MetaBag' => '"CMetaProperty"', 'OLEType' => '"CJobDefn"', 'Container' => '"V0"', 'NULLIndicatorPosition' => '"0"', '_type' => 'DSRECORD', '_children' => [ { 'Prompt' => '"/home/mi +gration/Dev root "', 'Default' => '"/home/m +igration/Dev"', 'ParamScale' => '"0"', 'ParamLength' => '"0"' +, '_type' => 'DSSUBRECOR +D', 'ParamType' => '"0"', 'Name' => '"ROOT"' }, { 'Prompt' => '"Business + Unit, ie WHUB"', 'Default' => '"CDBS"', 'ParamScale' => '"0"', 'ParamLength' => '"0"' +, '_type' => 'DSSUBRECOR +D', 'ParamType' => '"0"', 'Name' => '"SITE"' }, { 'Prompt' => '"Area of +Work ie AP"', 'Default' => '"AP"', 'ParamScale' => '"0"', 'ParamLength' => '"0"' +, '_type' => 'DSSUBRECOR +D', 'ParamType' => '"0"', 'Name' => '"AOW"' }, { 'Prompt' => '"DMR/Spec + ie Vendors"', 'Default' => '"Vendors +"', 'ParamScale' => '"0"', 'ParamLength' => '"0"' +, '_type' => 'DSSUBRECOR +D', 'ParamType' => '"0"', 'Name' => '"DMR"' }, { 'Owner' => '"APT"', 'Value' => '"#DSProjec +tARTOptions#"', '_type' => 'DSSUBRECOR +D', 'Name' => '"AdvancedRu +ntimeOptions"' } ], 'Readonly' => '"0"', 'NextID' => '"194"', 'ControlAfterSubr' => '"0"', 'TimeModified' => '"00.00.01"', 'CenturyBreakYear' => '"30"', 'Parameters' => '"CParameters"', 'JobType' => '"0"', 'DateModified' => '"1899-12-30"', 'Identifier' => '"ROOT"', 'FullDescription' => '"The first part of +the routine gathers data from the ABAP which extracts the necessary d +ata from the SAP tables KNA1 and KNB1 (NB the keys of the link betwee +n KNA1 and KNB1 will form the basis of all the ABAP queries)."', 'Description' => '"Collates all of the da +ta for the customer master migration."', 'Name' => '"AP_CDBS_Vendor_Summary"', 'Category' => '"1.FSS\\\\2.AP\\\\6.CDBS\\ +\\1.Vendors\\\\3.Reports"', 'IsTemplate' => '"0"' } ] };
|
|---|