I'm trying to extract DNC using Text::CSV. I have 5 columns, only 3 of them I'm using for this process which is columns "cleaned FDNC", "Clean" and "Cleaned_All", I've been working on this for a while and I can't seem to get it right. It should take Clean and Cleaned_FDNC and compare those numbers against Cleaned_All and which ever number is in Cleaned_all and isnt in the combination of the other 2 columns will be added to the DNC column. (a paragraph)

#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new({ binary => 1, auto_diag => 1, eol => $/ }); open(my $input, '<', 'output.csv') or die "Could not open output.csv: +$!"; open(my $temp_output, '>', 'temp_output.csv') or die "Could not open t +emp_output.csv: $!"; # This will hold all the numbers from the combined Clean and Cleaned_F +DNC my %combined_numbers; my $header = $csv->getline($input); # Read the header push @$header, 'DNC'; # Add the DNC column to header $csv->print($temp_output, $header); # Print the header to output # Process the header row my ($all_col, $clean_col, $fdnc_col, $invalid_col, $cleaned_all_col, $ +cleaned_fdnc_col) = @$header; my $dnc_col = ''; while (my $row = $csv->getline($input)) { next unless $row; # Skip undefined rows # Skip any row that matches the header pattern next if $row->[0] =~ /^all$/i && $row->[1] =~ /^clean$/i && $row-> +[2] =~ /^fdnc$/i; my ($all, $clean, $fdnc, $invalid, $cleaned_all, $cleaned_fdnc) = +@$row; # Record the numbers from Clean and Cleaned_FDNC columns $combined_numbers{$clean} = 1; $combined_numbers{$cleaned_fdnc} = 1; # If the number from Cleaned_All is not in the combined numbers of + Clean and Cleaned_FDNC, then it's DNC if (!exists $combined_numbers{$cleaned_all}) { $dnc_col = $cleaned_all; } # Print the data with DNC to the new output file $csv->print($temp_output, [$all, $clean, $fdnc, $invalid, $cleaned +_all, $cleaned_fdnc, $dnc_col]); } close($input); close($temp_output); # Rename the temporary file to output.csv rename("temp_output.csv", "output2.csv");

DNC is basically Do Not Call Numbers For the example i'll use 3 sets of data steming from the original.

&lt;p&gt;

All: 1111111111 2222222222 3333333333 1010101010 9999999999 8888888888

&lt;p&gt;

Clean: 9999999999 3333333333

&lt;p&gt;

FDNC: 1111111111 2222222222

To get the DNC we have to combine Clean and FDNC and compare it against All, so whatever number that is in All and isn't in Clean and FDNC, should be DNC. Clean and Federal Do Not Call(FDNC) is taken out of all originally, so whats left should be dnc, what ever isn't accounted for within the Federal Do not call lists.

&lt;p&gt;

Output: 1010101010 8888888888

Not sure how to do columns, but these sets are supposed to be columns in a csv.


In reply to Extracting DNC issues by MoodyDreams999

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.