Mike Stussie writes ..

>I'm a newbie to perl and trying to solve a problem.. Here is what I'm 
>trying to do:
>
>read thru flat file 'A' that looks something like this:(fields 
>delimited by
>'::')
>BCSNDTJN::Joe User::1 N.
>Main::Anytown::MO::None::None::None::Unknown::[EMAIL PROTECTED]
>
>and find any duplicates based on the email address that might be in
>flat file 'B'. I want to take the duplicates and output it to another
>file so that I can administer it later.
>
>I found something in the camel book relating to hashes that might do
>the trick but how do I get the flat file into a hash.


excuse me if I've misunderstood - but you seem to be having fun working
through things yourself and seem to be just looking for a solution to the
"how do I read a file into a hash" question .. rather than a solution to the
whole thing

so I'll just provide that - in case solving it all will be wrecking your fun
(let me know if I've guessed wrong .. because it's a very simple program to
show you)

also .. your description is unclear .. but I'm assuming that flat file 'B'
contains just email addresses .. eg.

  [EMAIL PROTECTED]
  [EMAIL PROTECTED]
  [EMAIL PROTECTED]

so .. here's the trick .. you use the map function to create a new list
where the lines from 'B' are the keys and you just give them a true value
(we're using 1 here)

  open IN, 'B' or die "Bad open: $!";
  my %check = map { chomp; $_ => 1 } <IN>;

so .. if the above example email addresses were in 'B' then now you'd have
the following hash

  $check = ( '[EMAIL PROTECTED]' => 1,
             '[EMAIL PROTECTED]'     => 1,
             '[EMAIL PROTECTED]'      => 1
           );

so hopefully your camel example will now enable you to look through 'A'
checking whether the email address is a duplicate

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/

Reply via email to