All source code in Perl Ask a Perl Pro Discussion Forum Categories All jobs in Perl
Command,line,Phone,Book,store,retrieve,Name,N
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Perl Stats

 Code: 92,430. lines
 Jobs: 57. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for Perl.
There is currently no new code. Please check back soon.
Click here to put this ticker on your site!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Phone Book

Print
Email
 
VB icon
Submitted on: 3/15/2003 6:25:55 PM
By: SpyderCo  
Level: Intermediate
User Rating: By 1 Users
Compatibility:5.0 (all versions), 4.0 (all versions)

Users have accessed this code 4720 times.
 
(About the author)
 
     Command line Phone Book for you to store and retrieve the Name, Phone Number, Email and address of someone you know.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    =**************************************
    = Name: Phone Book
    = Description:Command line Phone Book fo
    =     r you to store and retrieve the Name, Ph
    =     one Number, Email and address of someone
    =     you know.
    = By: SpyderCo
    =
    = Assumes:This version uses SDBM_File, i
    =     f you do not have this installed change 
    =     the two affiliated lines to DB_File.
    =
    =This code is copyrighted and has    = limited warranties.Please see http://w
    =     ww.Planet-Source-Code.com/vb/scripts/Sho
    =     wCode.asp?txtCodeId=426&lngWId=6    =for details.    =**************************************
    
    #!/usr/bin/perl -W
    use strict;
    use warnings;
    use POSIX;
    use Fcntl;
    # use DB_File
    use SDBM_File;
    my %dbm;
    my $test = "phone.dbm";
    my $name;
    #tie (%dbm, 'BM_File', $test, O_CREAT|O_RDWR, 0644)
    tie (%dbm, 'SDBM_File', $test, O_CREAT|O_RDWR, 0644)
    || die "Died tying database\nReason: $!";
    # Printing option menu
    print "Aaron's Phonebook System\n\n\n";
    print "f - find an entry\n";
    print "a - add an entry\n";
    print "m - modify an entry\n";
    print "d - delete an entry\n";
    print "r - read all entries\n";
    print "e - erase all entries\n";
    chomp(my $option = <STDIN>); 
    $option =~s/\r//;
    print "Option: $option\n";
    #Add An Entry
    if ($option eq 'a') {
    print "add an entry test!\n";
    print "Name:";
    chomp(my $name = <STDIN>);
    print "Phone number:";
    chomp(my $number = <STDIN>);
    print "Email Address:";
    chomp(my $email = <STDIN>);
    print "Address Line 1:";
    chomp(my $address1 = <STDIN>);
    print "Address Line 2:";
    chomp(my $address2 = <STDIN>);
    print "$name added to the list!\n";
    # combine all data into one nicely snug package...I hope
    $dbm{$name}=join "\0",$name,$number,$email,$address1,$address2;
    $dbm{$name} =~s/\cM//g;
    }
    elsif ($option eq 'r') {
    foreach my $key ( sort keys %dbm ) {
    my($name, $number, $email, $addr1, $addr2) = split "\0", $dbm{$key};
    print "$name\n$number\n$email\n$addr1\n$addr2\n\n\n";
    }
    }
    
    elsif ($option eq 'f') {
    print "Who are you looking for?\n";
    &find;
    }
    # Delete An Entry
    elsif ($option eq 'd') {
    print "What name would you like removed?\n";
    &del;
    }
    elsif ($option eq 'e') {
    print "To delete all entries press y, to cancel press n\n";
    &erase;
    }
    else {
    print "Wrong button!\n";
    }
    sub del {
    chomp(my $d = <STDIN>);
    if ($dbm{$d}) {
    delete $dbm{$d};
    print "$d deleted successfully\n";
    }
    else {
    print "$d not found\n";
    }
    }
    sub find {
    chomp(my $f = <STDIN>);
    # $f=~tr/\r\z//d;
    #$f =~s/\r\z//;
    $f =~s/\cM//g;
    if (exists $dbm{$f}) {
    my($name, $number, $email, $addr1, $addr2) = split "\0", $dbm{$f}; 
    print "$name\n$number\n$email\n$addr1\n$addr2\n\n\n";
    }
    else {
    print "Name $f cannot be found in the directory.\n";
    }
    
    } 
    sub erase {
    chomp(my $e = <STDIN>);
    $e =~s/\r//;
    if ($e eq 'y') {
    %dbm = ();
    
    print "All entries have been deleted.\n";
    }
    elsif ($e eq 'n') {
    print "Deleting process cancelled.\n";
    }
    else {
    print "Key was invalid, deletion process failed\n";
    }
    }
    untie %dbm;


Other 17 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | Perl Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2010 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.