So I have this script and .txt file that iv'e been messing with, brand new to hashing...i'm trying to make the script search for a partial email address, say I would type smith and it would return both email addresses for smith. I have made it so it can read the phone, email and name if I type, Smith,John, but not sure how to make (hash?) to just type smith and get both emails.

#!/usr/bin/perl -w open( PH, "customers.txt" ) or die "Cannot open customers.txt: $!\n"; while (<PH>) { chomp; ( $customer, $number, $email ) = ( split( /\s/, $_ ) ) [0,1,2]; $Customer{$customer} = $_; $Phone{$number} = $_; $Email{$email} = $_; } close(PH); print "Type 'q' to exit\n"; while (1) { print "\nCustomer? "; $customer = <STDIN>; chomp ($customer); $address = ""; $number = ""; if ( !$customer) { print "E-Mail? "; $address = <STDIN>; chomp $address; if (! $address) { print "Number? "; $number = <STDIN>; chomp $number; } } next if ( !$customer and !$address and !$number ); last if ( $customer eq 'q' or $address eq 'q' or $number eq 'q' ); if ( $customer and exists $Customer{$customer} ) { print "Customer: $Customer{$customer}\n"; print "Customer: $Customer{$customer}\n"; next; } if ($address and exists $Email{$address} ) { print "Customer: $Email{$address}\n"; next; } if ($number and exists $Phone{$number} ) { print "Phone: $Phone{$number}\n"; next; } print "Customer record not found. \n"; next; } print "\nAll done.\n";
Smith,John (248)-555-9430 jsmith@aol.com Hunter,Apryl (810)-555-3029 april@showers.org Stewart,Pat (405)-555-8710 pats@starfleet.co.uk Ching,Iris (305)-555-0919 iching@zen.org Doe,John (212)-555-0912 jdoe@morgue.com Jones,Tom (312)-555-3321 tj2342@aol.com Smith,John (607)-555-0023 smith@pocahontas.com Crosby,Dave (405)-555-1516 cros@csny.org Johns,Pam (313)-555-6790 pj@sleepy.com Jeter,Linda (810)-555-8761 netless@earthlink.net Garland,Judy (305)-555-1231 ozgal@rainbow.com

In reply to The Art of Hashing by Anonymous Monk

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.