Leser: 2
8 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
<root>
<regex name="nameCheck>qr/tr0nix/</regex>
<regex name="nrCheck>qr/^\d$/</regex>
<regex name="emptyCheck>qr/^$/</regex>
</root>
<root startAt="0">
<check id="0" onMatchAction="return">nameCheck</check>
<check id="1" onMatchCheck="2">nrCheck</check>
<check id="2" onMatchAction="return">emptyCheck</check>
</root>
1
2
3
4
5
6
7
8
9
10
11
12
13
my %regex;
$regex[nameCheck]="qr/tr0nix/";
$regex[nrCheck]="qr/^\d$/";
$regex[emptyCheck]="qr/^$/";
sub check {
my $line = shift;
return if ($line =~ $regex[nameCheck]);
if ($line =~ $regex[nrCheck]) {
return if ($line =~ $regex[emptyCheck]);
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#!/usr/bin/perl use strict; use warnings; use YAML::Tiny; use Data::Dumper; my $string = do{ local $/; <DATA> }; my $config = YAML::Tiny->read_string( $string )->[0]; my $code = ''; variable_declaration( \$code, $config->{root} ); print $code; sub variable_declaration{ my ($coderef,$config) = @_; for my $name ( keys %$config ){ if( ! ref( $config->{$name} ) ){ declare_scalar( $coderef, $config->{$name}, $name ); } elsif( ref($config->{$name}) eq 'HASH' ){ declare_hash( $coderef, $config->{$name}, $name ); } elsif( ref( $config->{$name} ) eq 'ARRAY' ){ declare_array( $coderef, $config->{$name}, $name ); } } } sub declare_hash{ my ($coderef,$config,$name) = @_; $$coderef .= 'my %' . $name . " = (\n"; for my $key ( keys %$config ){ my $val = $config->{$key}->{value}; $val = $config->{$key}->{type} eq 'qr' ? "qr/$val/" : $val; $$coderef .= "$key => $val,\n" } $$coderef .= ");\n"; } sub declare_array{ my ($coderef,$config,$name) = @_; $$coderef .= "\nmy \@$name = (" . join(",", map{ '"' . $_ . '"' }@$config ) . ");\n"; } __DATA__ --- root: regex: nameCheck: type: qr value: tr0nix nrCheck: type: qr value: ^\d$ emptyCheck: type: qr value: ^$ array : - 1 - 2 code: startAt: 0 check: - 0 : Action: return Regex: nameCheck - 1 : Check: 2 Regex: nrCheck - 2 : Action: return Regex: emptyCheck
8 Einträge, 1 Seite |