On Tue, Jan 15, 2002 at 02:55:42AM +0100, Bart Lateur wrote:
> 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.
length $3 doesn't throw a warning for some reason. $3 is probably ''
when the optional part doesn't match.
> 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:
Going for short, not pretty. The && approach is about half a line
shorter.
> (n.b. what's with that "foreach(<DATA>) { ... }" ???)
brain fart. Actually, for(<DATA>) is shorter than while.
With your printf trick in place its down to:
#!/usr/bin/perl -w # run this file with perl -x
seek(DATA,0,0);for(<DATA>){/^#!/&&last;/(\w+):/&&print("--== $1 ==--\n")&&
next;/(\w+)[ ]+ (\w+)(?:[ ]+(\d+))?/&&printf("%-8s: %s std_logic%s;\n",$1,
$2,length$3&&"_vector($3 downto 0)")&&next}
__DATA__
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
Nature is pissed.
http://www.unamerican.com/