On Mon, 14 Jan 2002 20:11:42 -0500, Michael G Schwern wrote:
> /(\w+)[ ]+ (\w+)(?:[ ]+(\d+))?/ &&
> do { $sl = length $3 ? "_vector($3 downto 0);" : ';';
> printf "%-8s: %s std_logic%s\n", $1, $2, $sl; next; };
If we like it -w clean: "length $3" will generate a warning if the
optional part isn't present, because then, $3 will be undefined. Thus:
testing defined($3) looks to be a better test, to me.
As perl booleans FALSE look like empty strings when used as a string,
this can become:
/(\w+)[ ]+ (\w+)(?:[ ]+(\d+))?/ &&
do { printf "%-8s: %s std_logic%s;\n", $1, $2, defined $3 &&
"_vector($3 downto 0)"; next; };
As for style... I prefer if(..) { ... } elsif (..) { ... } like this:
(n.b. what's with that "foreach(<DATA>) { ... }" ???)
#! perl -w
seek(DATA,0,0);
while (<DATA>) {
last if /^#!/;
if(/(\w+):/) {
print "--== $1 ==--\n";
} elsif(/(\w+)[ ]+ (\w+)(?:[ ]+(\d+))?/) {
printf "%-8s: %s std_logic%s;\n", $1, $2, defined $3 &&
"_vector($3 downto 0)";
} else {
print;
}
}
__DATA__
--
Bart.