B
Billy Patton
I'm checking the input to functions. The code below is just a snippett
The 'undef' is the problem.
It is being handled as a string.
What would be the simplest method of handling this?
use Data:
umper;
my %legal =
(
'extendInto'=> [
{'layer'=>'\S+','comment'=>'\S+','into'=>'\S+','value'=>'\d+','coincidenceOK'=>'[01]'},
];
my %seed = (
'layer'=>'CONT','comment'=>'xxxx',=>'into'=>undef,'value'=>20,'coincidenceOK'=>1
);
if (isLegal(\@{$legal{extendInto}},\%seed)){ print "legal\n"; }
else { print "NOT legal\n"; }
sub isLegal {
my $legalHashes = shift;
my $hashUnderTest = shift;
foreach my $legalTest (@$legalHashes) {
$Data:
umper::Indent = 0;
$Data:
umper::Terse = 1;
$Data:
umper::Sortkeys = 1;
$Data:
umper::Useqq = 1;
my $testRegex = Dumper $legalTest;
$testRegex =~ s/\\\\/\\/g; ## replace the excaped backslashes
$testRegex =~ s/uniq\d+-//g; ## delete the uniquifier prefix
$testRegex =~ s/\"/"?/g; ## make the quotes optional as it might be
string or an integer, we treat the same
$testRegex =~ s/\'/'?/g; ## make the quotes optional as it might be
string or an integer, we treat the same
$Data:
umper::Indent = 0;
$Data:
umper::Terse = 1;
$Data:
umper::Sortkeys = 1;
$Data:
umper::Useqq = 1;
my $stringUnderTest = Dumper $hashUnderTest;
print "stringUnderTest = $stringUnderTest\n";
print "testRegex = $testRegex\n";
return 1 if ($stringUnderTest =~ /$testRegex/);
}
return 0;
}
Here is the result of a run:
stringUnderTest = {"coincidenceOK" => 1,"comment" => "xxxx","into" =>
undef,"layer" => "CONT","value" => 20}
testRegex = {"?coincidenceOK"? => "?[01]"?,"?comment"? =>
"?\S+"?,"?into"? => "?\S+"?,"?layer"? => "?\S+"?,"?value"? => "?\d+"?
legal
The 'undef' is the problem.
It is being handled as a string.
What would be the simplest method of handling this?
use Data:
my %legal =
(
'extendInto'=> [
{'layer'=>'\S+','comment'=>'\S+','into'=>'\S+','value'=>'\d+','coincidenceOK'=>'[01]'},
];
my %seed = (
'layer'=>'CONT','comment'=>'xxxx',=>'into'=>undef,'value'=>20,'coincidenceOK'=>1
);
if (isLegal(\@{$legal{extendInto}},\%seed)){ print "legal\n"; }
else { print "NOT legal\n"; }
sub isLegal {
my $legalHashes = shift;
my $hashUnderTest = shift;
foreach my $legalTest (@$legalHashes) {
$Data:
$Data:
$Data:
$Data:
my $testRegex = Dumper $legalTest;
$testRegex =~ s/\\\\/\\/g; ## replace the excaped backslashes
$testRegex =~ s/uniq\d+-//g; ## delete the uniquifier prefix
$testRegex =~ s/\"/"?/g; ## make the quotes optional as it might be
string or an integer, we treat the same
$testRegex =~ s/\'/'?/g; ## make the quotes optional as it might be
string or an integer, we treat the same
$Data:
$Data:
$Data:
$Data:
my $stringUnderTest = Dumper $hashUnderTest;
print "stringUnderTest = $stringUnderTest\n";
print "testRegex = $testRegex\n";
return 1 if ($stringUnderTest =~ /$testRegex/);
}
return 0;
}
Here is the result of a run:
stringUnderTest = {"coincidenceOK" => 1,"comment" => "xxxx","into" =>
undef,"layer" => "CONT","value" => 20}
testRegex = {"?coincidenceOK"? => "?[01]"?,"?comment"? =>
"?\S+"?,"?into"? => "?\S+"?,"?layer"? => "?\S+"?,"?value"? => "?\d+"?
legal