perl - Extract data from two flat files using a key (phone_no) and print or purge matching records -


here set of final assignment

this final assignment.

i have been given fixed flat file withemployee list below.

employee (20 bytes) title (20 bytes) dept (13) phone (14)  example abad, rachel pr    clerk engineering   engr dist ofc  (818) 374-7538  abdullah, solom safety engr press    ves inspectio   (818) 374-9930   abel, darla sr       safety eng elevatorsinspection   (213) 202-9839   abraham, teresa sr mgmt analyst ii     res mgmt cus (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  

a second file contains list of phone numbers, happen on list of employee list.

(818) 374-9930 (213) 202-9902 (213) 482-0373 (818) 374-7538 

if there match, need extract , printout entire line (to file) testing check ensure able read hash. (terminated.dat)

!/usr/bin/perl  use strict; use warnings;  open phonelist, "< phonelist.txt" or die "could not open phonelist.txt\n"; $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;     ($phonekey) = ($_);     if (defined $phone_no->{$phonekey}) {         print stdout "$_\n";   } } close emprecord; 

i unable create hash or array read , compare 2 files , remove terminated accounts lists. please advise doing wrong.

in code reading whole line employee list $phonekey variable. need extract actual phone number searching.

i suggest adding:

$phonekey =~ s/.*(\([0-9]+\) [0-9]+\-[0-9]+)$/$1/; 

or similar.

actually, looking @ spec...

$phonekey = substr($_, -13); 

might better choice.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -