ktb wrote: > >From the book - > $addressbook{"Paddy Malone"} = { > address => "23, Blue Jay Way", > phone => "404-6599" > }; > > And then bring them back into the program to print out. > Thanks, > kent
Hi Kent, How about "don't do it"? Look, when your text shows an assignment statement such as this, it is simply an example of how to prime your hash--for testing purposes only--from within your code. The rule should be: NEVER hard-code your data. Data is one thing. Program code is another. To include coded functionality, use the "use" or "require" statements. To store and retrieve data: =>Devise a storage format appropriate to your data. For instance: =>=>CSV: "Paddy Malone", "23 Blue Jay Way", "404-6599" =>=>Tagged Sections [BEGIN ADDRESS] name=Paddy Malone address=23 Blue Jay Way phone=404-6599 [END ADDRESS] =>Develop a standard set of functions to store in this format and retrieve from it. =>When you need to add, delete or modify data, call the appropriate function to open and edit the data file. I'll give you an example for the second format. You just got a new entry for Paddy Malone, with the same address as above, but phone number 514-2233 [Paddy went cellular, say]. #assumed: "Paddy Malone" has been loaded into $CurrentMember{'name'} open IN, "< address_book.txt"; open OUT, "> address_book.tmp"; my $EnteredName = $CurrentMember{'name'}; my $Line; while (defined ($Line = <IN>) and !( $Line =~ $EnteredName) ) {print OUT $Line;} if (defined($Line) { #if existing record is found print OUT $Line; #this prints the "name=Paddy Malone" line, which, being the #key for the record, will not changed $Line = <IN>; while ( !($Line =~ /[END ADDRESS]/)) { chomp $Line; my ($attribute, $value) = split (/=/, $Line); if (defined ($CurrentMember{$attribute})) { $value = $CurrentMember{$attribute} } print OUT "$attribute=$value\n"; $Line = <IN>; } print OUT "$Line\n"; while (defined ($Line = <IN>)) {print OUT $Line;} } else { # Here goes code to append a new record if no existing record for # Paddy Malone is found } close IN; close OUT; rename "address_book.tmp" "address_book.txt"; At first galnce, this might seem like a lot of processing, but the thing is, you only have to do it once. Of course, the code above is only an example, and you would need to refine it for your purposes. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]