For this sort of thing I prefer to build up a string, and print the whole string at the end. This allows me to keep related things together: it scares me, for example, that there is so much distance between the point that you emit the public class $class\{ and the point you emit the closing '}'. Instead I might wrap it as something like:

sprintf <<CLASS, $class, $classdef; public class %s { %s } CLASS
.. and I'd probably end up putting it in a little function.

I do this because I find it more robust against future changes. Programs like this tend to get extended over time in a manner rather like the expansion of the universe - any two lines of code will tend to get further apart as time passes, and by the time the code emitting the '{' and the '}' are in separate source files you've created a big maintenance headache.

Another benefit of building up a string to be written at the end is that it doesn't create a (broken) output file if you break out of the program during the 'enter properties' loop.

Hugo


In reply to Re: A place for code reviews by hv
in thread A place for code reviews by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.