Newbie alert. I am writing a program to help me learn Perl a little better. I have many computer books which I let people borrow. I decided I needed to do was make a program that would list all of my books with their author (i.e. Larry Wall - Programming Perl). I have the program open up a simple database separated by ":". From there it organizes the information. I am working on the borrow section of the database. I want the user to be able to enter in a books name, see if I have it and if it is available. If it is, the program will ask for their name and put the information into a hash. This part works well, but what is happening is it is not reading it back out to the file when it is done, instead it erases anything that is borrowed (including other authors) and erases the other books written by that author as well. Here is the borrow section of the code. Any suggestions would be greatly appreciated.
print "What Book would you like to borrow? "; my $book_to_borrow =<STDIN>; chomp $book_to_borrow; if (exists($borrowed_DB{$book_to_borrow})) { if (defined($borrowed_DB{$book_to_borrow})) { print "This book is not available for checkout\n"; } else { print "This book is available for checkout. \nPlease type your name: "; my $borrower = <STDIN>; $borrowed_DB{$book_to_borrow} = $borrower; } } else { print "Sorry. Not Available.\n"; }

In reply to Hashes/ Simple Database by bmhm

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.