#!/usr/bin/perl use warnings; use strict; use Date::Calc qw( Today Add_Delta_Days ); # This program takes input from a data dump # (CSV format) and produces the migration prep file # with very little user input at prompt. my $file = $ARGV[0]; my $num_args = $#ARGV + 1; die "ERROR: Usage: prep_gen.pl subs_dump_file.csv\nPlease provide file name\n" if ($num_args != 1); #Confirm .csv format my $period = rindex($file, "."); die "Invalid file format; must be .csv extension.\n" if ($period == -1); die "Invalid file format; must be .csv extension.\n" if (uc(substr($file, $period)) !~ /\.CSV$/); my $fileName = substr($file, 0, $period); open(my $infile, "<", $file) or die "Cannot open $file for reading!\n"; open(my $outfile, ">", $fileName."-migration-prep.txt") or die "Cannot open outfile for writing!\n"; # This will be the prep file created # We need the merchant name and customer ID # This is the only prompted input print "Please provide the full merchant name: \n"; my $merchName = <>; chomp($merchName); print $outfile "completeMerchantName=$merchName\n"; # Start adding content to outfile my ($year, $month, $day) = Today(); # Calc today's date for next date calc ($year, $month, $day) = Add_Delta_Days($year,$month,$day,60); # Conclude date for migration will be +60 days $month = sprintf("%02d", $month+1); $day = sprintf("%02d", $day); print "NOTE: migration conclude date set to $year-$month-$day 00:00:00\n"; print $outfile "cleanupDate=$year-$month-$day 00:00:00\n"; print "Please provide the customer ID as it appears in the DB: \n"; my $customerId = <>; chomp($customerId); while ($customerId !~ /^[0-9]+$/) { # Customer ID must be numeric print "Invalid input; customer ID must be completely numeric. Please try again: \n"; chomp($customerId = <>); } print $outfile "subscriptionDb.customerId=$customerId\n"; #### mmusser@localhost:~/programming/perl$ perl prep_gen.pl some_file.csv Please provide the full merchant name: NOTE: migration conclude date set to 2012-08-02 00:00:00 Please provide the customer ID as it appears in the DB: Use of uninitialized value $customerId in scalar chomp at prep_gen.pl line 50, <> line 1. Use of uninitialized value $customerId in pattern match (m//) at prep_gen.pl line 52, <> line 1. Invalid input; customer ID must be completely numeric. Please try again: