I'm trying to create a log file, to log phone numbers in the file that aren't 10 digits, been searching the documentation on adding an array variable into the log file, but had no such luck , I need some guidance.
# Read in all rows from existing file
my $rows = read_excel($in_file);
my $headers = [
"source_id",
"first_name",
"middle",
"last_name",
"address1",
"city",
"state",
"postal_code",
"phone_number",
"address3",
"province",
"email",
];
my $CA_zip = 19005;
# Update the rows
for my $row (@$rows) {
if ($row->[6] eq 'CA' && ! $row->[7]) {
$row->[7] = $CA_zip;
}
elsif ($row->[8] >10 || $row->[8] < 10) {
my $a = ($rows);
}
}
# add headers as first row
unshift(@$rows, $headers);
# Write the updated rows to new file
my $col_num = scalar @$headers - 1;
write_excel($out_file, $rows, $col_num);
sub read_excel {
my ( $file, $sheet ) = @_;
$sheet ||= 0;
my $parser = Spreadsheet::ParseXLSX->new();
my $workbook = $parser->parse($file);
if ( not defined $workbook ) {
die $parser->error;
}
my $worksheet = $workbook->worksheet($sheet);
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
my @rows;
for my $row ( $row_min .. $row_max ) {
my @cells;
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
if (not $cell) {
push(@cells,'');
next;
}
my $value = $cell->value();
push(@cells,$value);
}
push(@rows,\@cells);
}
return \@rows;
}
sub write_excel {
my ( $file, $rows, $col_max ) = @_;
my $workbook = Excel::Writer::XLSX->new( $file );
if ( not defined $workbook ) {
die "Could not open file: $!";
}
my $worksheet = $workbook->add_worksheet();
my $worksheet2 = $workbook->add_worksheet();
my $row_num = 0;
for my $row ( @$rows ) {
for my $col (0 .. $col_max) {
$worksheet->write( $row_num, $col, $row->[$col] );
}
$row_num++;
use Log::Log4perl qw(get_logger);
#Defining configuration
my $config = q(
log4perl.logger = ERROR, FileApp
log4perl.appender.FileApp = Log::Log4perl::Append
+er::File
log4perl.appender.FileApp.filename = test.log
log4perl.appender.FileApp.layout = PatternLayout
log4perl.appender.FileApp.layout.ConversionPattern = %d> %
+m%n $a
);
#logging behavior
Log::Log4perl->init( \$config );
my $logger = Log::Log4perl::get_logger("");
$logger->error("Oh my, a dreadful error!");
$logger->warn("Oh my, a dreadful warning!");
}
$workbook->close();
return;
}