Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

PerlbeginnercliAI generated

CSV Contact Merger

Build a Perl script that merges two contact lists exported as CSV files (for example from two email programs or phones), matching people by their email address. Emails are normalized first (lowercase and extra spaces removed), so Ana@Example.com and ana@example.com count as the same person. Contacts found in only one file are kept, contacts found in both are combined, and when the two files disagree on a field (such as two different phone numbers), the script records the conflict in a report instead of silently picking one. It's a good first Perl project: you'll learn reading and writing CSV properly with Text::CSV, hashes keyed by email, normalizing text, comparing records, and testing with Test::More.

Estimate
~6.5h
Steps
5
Completed by
0
Proposed by
codeseed.app

Text::CSV · Getopt::Long · Test::More

Project roadmap

  1. 01

    Define the inputs and outputs

    ~1h

    Write README.md: the input files (CSV with a header; the column names may differ, such as Email or E-mail Address, so the script maps known names), the outputs (merged.csv with one row per person, and conflicts.csv listing each disagreement with the email, field and both values), the rule for conflicts (keep the value from the file given with --prefer, and report it), and how rows without an email are handled (kept as they are and listed as unmatched). Done when: README.md defines the files, rules and outputs.

  2. 02

    Read the CSV files

    ~1.5h

    Read both files with Text::CSV (with binary => 1 and auto_diag, so quoted commas and line breaks work), map their headers to standard field names (name, email, phone and company), and store each row as a hash. Report rows with parsing problems and continue. Done when: both sample files load into lists of hashes with standard field names.

  3. 03

    Normalize and match by email

    ~1h

    Write a normalize_email function (trim spaces and lowercase) and store each file's contacts in a hash keyed by the normalized email, reporting duplicate emails within the same file. Done when: contacts from both files are matched by email, including different capitalization.

  4. 04

    Merge and report conflicts

    ~1.5h

    For each email found in either file, combine the fields: take a value when only one file has it, and when both have different non-empty values (comparing phone numbers by their digits only), keep the preferred file's value and add a line to the conflicts list. Write merged.csv and conflicts.csv with Text::CSV, sorted by email, and print a summary (only in file 1, only in file 2, merged, and conflicts). Done when: the merged file and conflicts report are correct for the sample files.

  5. 05

    Test it

    ~1.5h

    Write Test::More tests with small CSV files created in the test: email normalization, header mapping, contacts only in one file, merging with and without conflicts, phone numbers in different formats, rows without an email, and quoted fields with commas. Done when: prove -l t/ passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~6.5h · 5 steps

Tech stack

Text::CSVGetopt::LongTest::More