LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 301 users online 225185 members 396 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
MajorT0M
Music: R.E.M., Death Cab For Cutie, Eels, Mew,...
Mood: Frustrated
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
1 online / 38 MPM
Christmas Eve
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Adding Reply
Topic Library of Alex
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
GdFtherOFCOWS Posted at 11:58 am on June 10, 2009
Because I am in between projects at work, I decided to make a Tower of Babel simulator but with 10000 character pieces instead of the 1,090,000 some odd that the original had.

Code:
#!/usr/bin/perl

print "Welcome to the Library of Alex, located directly under the Library of Babel.";
sleep(4);
MainScreen();

sub MainScreen{
print "\n\n";
print "What would you like to do?\n";
print "1. Find random book.\n";
print "2. Find specific book. **Out of Order**\n";
print "3. About the Library of Alex\n";
print "4. Exit Library Program.\n";
$answer = <>;

if ($answer == "1"){
RandomBook();
}
if ($answer == "2"){
print "Being as there are more books here than the number of atoms in the universe, it is taking us some time to cataloged everything.  Please try again later.";
MainScreen();
}
if ($answer == "3"){
print "\nThe Library of Babel above us contains every possible combination of basic      characters (letters, spaces and punctuation marks) for a 410-page book.         'Who has time for that?' says the Alex, the lead librarian for The Library of   Alex.  His library instead of containing every possible combination of 410 page books, instead houses every single flash story of 10000 characters.";
MainScreen();
}
if ($answer == "4"){
exit();
}
else{
print "\nThat's not a valid selection!";
MainScreen();
}
}

sub RandomBook{
# This is the characters array for the story
# It has every letter in upper and lowercase, and . ! ? in punctionation marks

@letters = PRETEND
$x = 0;
$book = "";

#Gets book
while ($x < 10000){
my $range = 57; # Number in array + 1
my $random_number = int(rand($range));

$book = join $book, "", $letters[$random_number];

$x++;
}

unlink("book.txt");

open (MYFILE, ">>book.txt");
print MYFILE "$book";
close (MYFILE);


print "Your book has been selected!  Please go to the location of this program and readthe book text document.";
MainScreen();
}

Where the @letters array is, pretend there is the array there.  LW has that thing about 100 characters in a row.

Replies
GdFtherOFCOWS Posted at 8:26 pm on June 11, 2009
Quote: from Sector Corrupt at 10:24 pm on June 11, 2009

I borrowed some code from the repository and it was perfectly readable even without comments.

That kinda code makes me want to give the person a handjob

Sector Corrupt Posted at 8:24 pm on June 11, 2009
Quote: from GdFtherOFCOWS at 11:21 pm on June 11, 2009

Quote: from Sector Corrupt at 10:20 pm on June 11, 2009

Least it's a good habit. I currently only comment when I'm stuck and need something to keep me busy while I think out the problem.  That, and my work I think is a little lax on the whole code thing, as long as it works.  

God I hate people who don't comment. Makes my life hell when I have to clean up after them


Yeah, were anyone working on my project beside me I'd make sure to comment as I go along, but for now I mostly only pepper comments here or there and leave it to be cleaned up when I'm done. Right now I'm just trying to get a version we can roll out to our remote boxes.

But yeah, good commenting is great. Or at least clear code. I borrowed some code from the repository and it was perfectly readable even without comments.

GdFtherOFCOWS Posted at 8:21 pm on June 11, 2009
Quote: from Sector Corrupt at 10:20 pm on June 11, 2009

Least it's a good habit. I currently only comment when I'm stuck and need something to keep me busy while I think out the problem. That, and my work I think is a little lax on the whole code thing, as long as it works.

God I hate people who don't comment.  Makes my life hell when I have to clean up after them

Sector Corrupt Posted at 8:20 pm on June 11, 2009
Quote: from GdFtherOFCOWS at 9:44 pm on June 11, 2009

Quote: from Sector Corrupt at 3:20 am on June 11, 2009

Fairly interesting, and the first time I've seen Perl used on LW oddly enough, sans my signature. Plus it's nice seeing clear code that is readable in perl, after hacking together my overly complicated script... But oh well, such is life.

Concerning readable code, I blame my teacher. She counted off if we didn't have comments in the code, and counted off more if someone couldn't understand it without the comments.


Least it's a good habit. I currently only comment when I'm stuck and need something to keep me busy while I think out the problem.  That, and my work I think is a little lax on the whole code thing, as long as it works.  

GdFtherOFCOWS Posted at 6:44 pm on June 11, 2009
Quote: from Sector Corrupt at 3:20 am on June 11, 2009

Fairly interesting, and the first time I've seen Perl used on LW oddly enough, sans my signature. Plus it's nice seeing clear code that is readable in perl, after hacking together my overly complicated script... But oh well, such is life.

Concerning readable code, I blame my teacher.  She counted off if we didn't have comments in the code, and counted off more if someone couldn't understand it without the comments.

Sector Corrupt Posted at 1:20 am on June 11, 2009
Fairly interesting, and the first time I've seen Perl used on LW oddly enough, sans my signature. Plus it's nice seeing clear code that is readable in perl, after hacking together my overly complicated script... But oh well, such is life.
bella elizabeth swan Posted at 11:59 am on June 10, 2009
Post from this position was omitted due to content violations
All 7 previous replies displayed.