sub parse_options { # \%options_we_can_write, \@lines_of_options_file. [ $die_on_extra_options ] #loads all matching values from an array of lines into the options hash #uses '=' as the separator, one ( 1 ) space on either side my ($options_we_can_write, $options_file_lines, $die_on_extra_options) = @_; my $var = ""; my $sigil = ""; my $val = ""; my $setter = ""; my $arraything = ""; my $fd = ""; my $rd = ""; my $index = ""; if( ! %{$options_we_can_write} ){ die "no options to match\n" } foreach ( @{ $options_file_lines } ){ if( $_ =~ m/ ^([@%\$]?) # open sigil ([a-zA-Z_]+) # variable (\[)? #optional open bracket ([\d]*) #optional number (])? #optional close bracket \ # space = # equals \ # space ([a-zA-Z0-9_\\\/:]+)$ # string until end of line /x #end regex ){ #startif #print "##$1## ##$2## ##$3## ##$4## ##$5## ##$6##\n"; #complains about undefined values if( defined ($sigil = $1) eq "" ){ $sigil = '$' } print "####sigil $sigil ##>$1<##\n"; $var = $2; if( defined ($fd = $3) eq "" ){ $fd = "" }; if( defined ($index = $4) eq "" ){ $index = "" } if( defined ($rd = $5) eq "" ){ $rd = "" }; if ( ($fd eq '[' and $rd ne ']') or ($fd eq "{" and $rd ne '}') ){ print STDERR "Mismatched delimiters for $var, skipping\n"; next; } if ( ($fd eq '[' and $rd eq ']') and ( ! is_whole_number($index) ) ){ print STDERR "array assignment $var needs whole number index\n"; next; } # if ($fd eq "{" and $rd != '}' ){ # print STDERR "Error bad delimiter for $var"; # } $setter = "$sigil\{ \$options_we_can_write->{$var} }$fd$index$rd = $val"; print "$setter\n"; if( exists $options_we_can_write->{"$var"} ){ eval $setter; } next; } if( $_ =~ m/^(.*?) = (.*)$/ ){ $var = $1; $val = $2; if( exists $options_we_can_write->{"$var"} ){ ${ $options_we_can_write->{"$var"} } = $val; } else { print "Error: desired option $var not found\n"; } } #print "$_\n"; } return 0; } #### if( defined ($fd = $3) eq "" ){ $fd = "" }; #### if( defined ($fd = $3) eq "" ){ $fd = "ssssssssss" };