kume8sit has asked for the wisdom of the Perl Monks concerning the following question:

Here is another set of my final assignment This is my final assignment. I have been given a fixed length employee list below. ABAD, RACHEL PR CLERK ENGINEERING ENGR DIST OFC (818) 374-7538 ABDULLAH, SOLOMON SAFETY ENGR PRESS VES INSPECTION (818) 374-9930 ABEL, DARLA SR SAFETY ENG ELEVATORSINSPECTION (213) 202-9839 ABRAHAM, TERESA SR MGMT ANALYST II RES MGMT CUST (213) 482-6766 ABRAMYAN, DANIEL INACTIVE NONE NONE ABREU, JAMES BUILD MECH INSPECTORCODE ENFCMNT (818) 374-9862 ACEVEDO CASTRO, MECH ENGRG ASS ENGINEERING (213) 202-9902 ACOSTA, JESUS GEOTECH ENGINEER II INSPECTION GRADING (213) 482-6967 AGHAZARIAN, SAKO SRBUILD INSPECTOR INSPECTION BLDG(213) 482-0372 Also I have been given a second list of phone numbers, which happen to be on the list of employee list. (818) 374-9930 (213) 202-9902 (213) 482-0373 (818) 374-7538 If there is a match, I need to extract and printout the entire line (to another file) but for now I am testing check to ensure am able to read the hash.. !/usr/bin/perl use strict; use warnings; open PHONELIST, "< PHONELIST.TXT" or die "could not open PHONELIST.TXT\n"; my $phone_no; while (<PHONELIST>) { chomp; $phone_no->{$_} = 1; print "$phone_no\n"; } close PHONELIST; open EMPRECORD, "< EMPRECORD.TXT" or die "could not open EMPRECORD.TXT\n"; while (<EMPRECORD>) { chomp; my ($phoneKey) = ($_); if (defined $phone_no->{$phoneKey}) { print STDOUT "$_\n"; } } close EMPRECORD; I am unable to create the hash to read and compare. Please advise what I am doing wrong.

Replies are listed 'Best First'.
Re: Data Manipulation.
by GrandFather (Saint) on Nov 28, 2014 at 06:11 UTC

    So you have given us an overview of your homework task, but you don't tell us what you are having trouble with nor show us the code that isn't doing what you want so we can't help you much beyond saying: read the documentation and have a look through the Tutorials.

    If you want specific help you need to ask a specific question. For help with how to ask see I know what I mean. Why don't you?.

    Perl is the programming world's equivalent of English
Re: Data Manipulation.
by CountZero (Bishop) on Nov 28, 2014 at 19:24 UTC
    Any company that wants you to use 4 flat files instead of a database to handle this kind of task isn't worth to employ a Perl programmer.

    Even as homework it is rather silly.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Data Manipulation.
by rahulruns (Scribe) on Nov 28, 2014 at 06:33 UTC

    To give you an idea how to do it, take the phone number from file A. I hope it contains only phone numbers. Read that file line by line. See sample code below for line by line reading of file in PERL. Then match the phone number from here in file B and do what you want to do with it. This is one of the ways. There are others ways also to achieve it

    my $filename = <yourfile> while (my $row = <$filename>) { chomp $row; print "$row\n"; }