Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • i usually write that as

    perl -le 'print chr(65+rand(26))'

    your version is prettier, though :)

    (sorry, i'm not a java person)
    bgp is for those who can't keep it static long enough
    • Damn. I thought my version is crystal clear, but yours is just perfect and obvious -- if you know ASCII.

      And doing that in Java:


      class Pick {
          public static void main(String[] args) {
              BufferedReader br = new BufferedReader(new InputStreamReader(;
              while (true) {
                  try {

      • I Don't Speak Java, But:

        If this is for a party game, isn't the exception handling gratuitous? Whether it fails with a stack track or a nice error message, it's screwed up. Can't you just omit that?

        Why do you need the reader at all? Is there some requirement that you must read from stdin if you want to send to stdout?
        • As Ovid points out, you do have to do something about the exception because it is a checked exception. But my preferred choice in this case would be to declare that main() throws the exceptions [], thus letting the calling environment handle it, because, as you say, if it's screwed up, it's screwed up, no matter how it chooses to express the failure.

          Ovid, did you know you could throw exceptions from main()?

          How much have we shortened your Java code, now? :)

          J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
          • I had never heard of checked exceptions. I can see their value, but I think I'd find the more irritating than useful unless I could disable them for one-offs.

            • Checked exceptions are evil. They sound good, until you try them. Bruce Eckel, the author of Thinking in Java [], has a great essay about the problems with checked exceptions [].

              • Checked exceptions are extremely valuable when designing or using APIs. Most of the pain comes from misuse. Used properly, you only have to deal with them when you really should write error handling anyway. But I didn't create this account to enter that endless debate. I just wanted to point out that its in the nature of the difference strengths of Java and Perl that you can't post a piece of code where Java is more natural. Its only when dealing with large bodies of code that Java's strength is appare