Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

perl and linked lists

Posted on 2004-10-25
11
Medium Priority
?
877 Views
Last Modified: 2010-05-18
I need to write a program which similates a "Rolodex".  
Each page should contain the following information:

      First_Name      Last_Name                   Phone_Number

The program should be menu driven, with the following options:

      1) Add a page,
      2) Search for a page by last name,
      3) Search for a page by phone number,
      4) Remove a page (found by searching by last name).
      5) Print out the whole rolodex sorted by last name.

the program must use linked lists.  Each page should be represented by a
hash, and the reference to the hash should be stored as the value of a node
in the linked list.  When a new node is inserted, it should be inserted into
the list so as to preserve alphabetical ordering.  
0
Comment
Question by:police45s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 18

Expert Comment

by:kandura
ID: 12406463
I'd suggest using a database for the backend, DBI with DBD::SQLite, and Class::DBI for the model.
0
 
LVL 8

Accepted Solution

by:
davorg earned 672 total points
ID: 12409519
You tend not to use linked lists in Perl as arrays, hashes and other more complex data structures are usually more efficient.

Dave...
0
 
LVL 18

Assisted Solution

by:kandura
kandura earned 664 total points
ID: 12409850
jmcg,
> If you're just learning Perl, and don't already have experience with SQL
> or databases, I don't know that I can second Kandura's suggestion.

Hence the recommendation to use Class::DBI. All you need to know is how to create the base table, and CDBI will wrap each row in an object. There is no SQL in view anywhere :-)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:police45s
ID: 12417142
I understand and appreciate your comments, but this is the way that the program must be constructed, with a linked list.  I have worked on a single occasion with linked lists but the data that was being passed was just a scalar variable(a number).  This linked list is supposed to be created using a hash (for the 3 data fields), and the reference to the hash should be stored as a value of a node in the linked list.  This is the problem I'm having and unfortunately I can't get very far into the code unless I can constuct this hash and the reference to the hash.  Any help would be appreciated.
0
 
LVL 20

Assisted Solution

by:jmcg
jmcg earned 664 total points
ID: 12418355
Kandura -

I'll have to try that once I get my system back to working (HD failed, dammit).

Dave -

A reminder on hashes and hash references to maybe get you started:

You can initialize a hash via an array assignment. Here's a sloppy linked list example:

    %LList = ( next=>undef, content=>undef);

New elements can be anonymous hashes

     $LList{next} = { next=>undef,
            content=>{FirstName=>'James', LastName=>'Mason', Phone=>'555-1212' }
          };

I've made the content into a sub-hash rather than have them mix in with the namespace with 'next'  but that's a matter of taste and probably inefficient.

When you go to add another element, you start with

      $cursor = \%LList;

and chase down the linked list to find where to insert the new element:

       while( $cursor->{next}  && $cursor->{next}{content}{LastName} < $NewLastName ) {
                $cursor = $cursor->{next};
                }
        $cursor->{next} = { next=>$cursor->{next},
                  content=>{FirstName=$NewFirstName, Lastname=>$NewLastName, Phone=>$NewPhone}
                };
       
0
 
LVL 18

Expert Comment

by:kandura
ID: 12678394
jmcg,
I don't believe I deserve points for this topic, since my recommendation didn't satisfy the OP's requirements.

Good to see you back in cleaning though!

Sometimes I wish we had something of a chat room within this topic area. It would be nice to have a talk with you and the other experts on occasion.
Something I'd like to mention for example (even though it's not relevant to this particular topic) is that I'm in the process of moving to another country (Norway, to be precise) with my wife, so my activities on EE will be rather sporadic over the coming month.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question