MoodyDreams999 has asked for the wisdom of the Perl Monks concerning the following question:
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.
<p>All: 1111111111 2222222222 3333333333 1010101010 9999999999 8888888888
<p>Clean: 9999999999 3333333333
<p>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.
<p>Output: 1010101010 8888888888
Not sure how to do columns, but these sets are supposed to be columns in a csv.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Extracting DNC issues
by choroba (Cardinal) on Oct 04, 2023 at 21:25 UTC | |
by MoodyDreams999 (Scribe) on Oct 06, 2023 at 21:42 UTC | |
Re: Extracting DNC issues
by chromatic (Archbishop) on Oct 04, 2023 at 21:41 UTC | |
by MoodyDreams999 (Scribe) on Oct 06, 2023 at 21:39 UTC | |
by chromatic (Archbishop) on Oct 07, 2023 at 17:09 UTC | |
by MoodyDreams999 (Scribe) on Oct 09, 2023 at 15:26 UTC | |
by chromatic (Archbishop) on Oct 10, 2023 at 00:31 UTC | |
by NERDVANA (Priest) on Oct 07, 2023 at 03:59 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 07, 2023 at 05:14 UTC | |
by kcott (Archbishop) on Oct 07, 2023 at 06:08 UTC | |
| |
Re: Extracting DNC issues
by NERDVANA (Priest) on Oct 10, 2023 at 06:56 UTC |