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
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
also a favourite (Score:1)
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
Reply to This
Re: (Score:2)
Damn. I thought my version is crystal clear, but yours is just perfect and obvious -- if you know ASCII.
And doing that in Java:
Re: (Score:1)
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?
rjbs
Re: (Score:2)
The reason for the reader is that the game were were playing required we think of words for categories but each word had to start with a particular letter. The reader was there to ensure we could just hit "Enter" and get the next letter. So if we just rerun java Pick every time, we can get it to this:
This doesn't replicate the exact
Re: (Score:2)
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 [perl.org], 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
Re: (Score:1)
Thanks!
rjbs
Re: (Score:2)
Checked exceptions are evil. They sound good, until you try them. Bruce Eckel, the author of Thinking in Java [amazon.com], has a great essay about the problems with checked exceptions [mindview.net].
Re: (Score:1)
Re: (Score:1)
Funny; I consider Java's encouragement to produce large bodies of code a disadvantage.
Re: (Score:2)
Okay, I got a half-million lines of Java here, judging by just a second ago when I did a find . -name '*.java' | xargs wc -l. When do the advantages start becoming apparent?
(Okay, to be fair, I can see some advantages. But if I were starting this from scratch, yes, it would be Perl!)
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Re: (Score:2)
That can come across as slightly more documented if you say:
Then you don't have the potentially mystifying 65. (I fess up; I always have to look up the value of 'A' on an ASCII chart whenever I want to do anything like this.)
Some languages will basically treat 'A' as an int and allow you to drop the ord(). Not Perl. Might work for Java, though.
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Re: (Score:1)
perl -le'$a="A";$a++for 1..rand 26;print$a'