Without bothering with the GUI framework, here's a possible general approach to handling the VALUEs file:
c:\@Work\Perl\monks>perl
use strict;
use warnings;
use autodie;
use Data::Dump qw(dd);
my @tags = qw(NAME TASK CAPS PKG_TYPE STACK SHIP);
my $rx_value_intro = qr{ \s* [|] \s* VALUE \s+ = \s+ }xms;
my $rx_value = qr{ [[:alnum:]]+ }xms;
my ($rx_tag) =
map qr{ \b (?: $_) \b }xms,
join ' | ',
map quotemeta,
reverse sort
@tags
;
print "rx_tag $rx_tag \n"; # for debug
my $data_file = <<'EOF';
NAME|VALUE = a
TASK|VALUE = copy
CAPS|VALUE = 0
PKG_TYPE|VALUE = premium
NAME|VALUE = z
TASK|VALUE = cut
CAPS|VALUE = 0
PKG_TYPE|VALUE = premium
NAME|VALUE = c
TASK|VALUE = paste
STACK|VALUE = 2
SHIP|VALUE = lowtier
EOF
open my $fh_input, '<', \$data_file;
local $/ = '';
while (my $record = <$fh_input>) {
my $got_params =
my %params =
$record =~ m{
\G \s*
($rx_tag) $rx_value_intro ($rx_value) \s+
}xmsg;
die "bad params record '$record'" unless $got_params;
# dd \%params; # for debug
process_params(%params);
}
sub process_params {
my (%params,
) = @_;
print "processing params: @{[ %params ]} \n";
}
__END__
rx_tag (?msx-i: \b (?: TASK | STACK | SHIP | PKG_TYPE | NAME | CAPS) \
+b )
processing params: NAME a PKG_TYPE premium TASK copy CAPS 0
processing params: NAME z PKG_TYPE premium TASK cut CAPS 0
processing params: STACK 2 NAME c SHIP lowtier TASK paste
See haukex's article Building Regex Alternations Dynamically. Of course, much testing of the code is needed.
Give a man a fish: <%-{-{-{-<
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|