#!/usr/bin/perl use Business::CreditCard; ####################################################################### # Author: Fachtna Roe: Date: 20090304 # # Program: make-data-2009.pl Purpose: generate psuedo reservations # # to assist in tesing assignment # ####################################################################### $sample_data_file = "/home/public/00-2009-sample-reservations.dat"; print "<-Generate psuedo data for 2009-#2->\n"; print "Generate how many records? "; $target = ; print "Store in file: [$sample_data_file]? "; $file = ; chomp $file; if ($file ne "") { $sample_data_file = $file; } print "Generating...\n"; $sc = ":"; $scripter = "TestData-FR"; ################ START DATA POOL ################# @first_name = ("John", "Mary", "Phillip", "Ryan", "Susan", "Sarah", "", "William", "Niamh", "Alice", "Nuala", "Patricia", "Steven", "", "", "", "Noel", "Laura", "Ciara", "Niamh", "Alice"); @last_name = ("Williams", "Ryan", "", "Smith", "Kennedy", "", "Wilkinson", "", "FitzPatrick", "Quinn", "Noyak", "Slattery", "Brennan", "", "Ryan", "Moore", "Butler", "O'Reilly", "Murphy", "Kilduggan"); @users = ("me23", "oopsy", "tarball", "king 96", "king96", "", "whoa mi", "vicar", "topdog91", "elfin01", "fubar", "bruges_02", "po rky", "scarper", "abc", "gnasher007", "turk182", "beastie", "lover", "the_gannet"); @domains = ("yahoo", "gmail", "g mail", "googlemail", "hotmail", "fastmail", "kitchens", "sparkers", "tinet", "", "horri net", "horrinet"); @tlds = ("ie", "org", "net", "", "", "com", "co.uk", "eu", "fr", "to", "biz", " biz", "in fo", "info"); ################# END DATA POOL ################## open (FILE, " > $ sample_data_file") or die $!; $record_count = 0; while ($record_count < $target ) { # Generate random names and email addresses from data pool above $name = $first_name[int(rand(@first_name)+1)]." ".$last_name[int(rand(@last_name)+1)]; $email = $users[int(rand(@users)+1)]."@".$domains[int(rand(@domains)+1)].".".$tlds[int(rand(@tlds)+1)]; # Generate random dates and numeric values for psuedo reservations $year = 2009+(int(rand(2))); $date = int(rand(30)+1)."/".int(rand(12)+1)."/".$year; $days = int(rand(21)); if (int(rand(2))==1) { # 50/50 drop days ... why not? $days = ""; } $adults = int(rand(16)); $kids = int(rand(16)); $vholder = uc($name); ########################################################## # Generate valid and invalid visa numbers $num = rand(1); $num = int($num * 100000000000000); # 0.12345678901234 becomes 123456789012340 (sort-of) $num = "4".$num; $vlength=length($num); # print "$vlength\n"; # Used for debugging # Deal with 14 and 15 digit numbers. Abandon others as errors. if ($vlength < 14 ) { # Do nothing (could be a valid 13 digit number!) } elsif ($vlength == 14) { # Make up to an invalid 16 digit number $num = int(rand(2)).int(rand(2)).$num; } # Pad to 16 digits, invalid elsif ($vlength == 15) { $toincoss = int(rand(4)); if (($toincoss == 1) || ($toincoss == 3)) { $last_digit = generate_last_digit ($num); } # Pad to 16 digits 'randomly' valid else { $last_digit = int(rand(10)); } # Pad to 16 digits 'randomly' invalid $num = $num.$last_digit; } # elseif $vlength=length($num); $vnumber = $num; $vyear = 2009+(int(rand(2))); $vexpiry = int(rand(12)+1)."/".$vyear; # Assemble the record $record=$scripter.$sc.$name.$sc.$email.$sc.$date.$sc.$days.$sc.$adults.$sc.$kids.$sc.$vholder.$sc.$vnumber.$sc.$vexpiry."\n"; ########################################################## #print "> $record \n"; # Debuggin output used while developing print FILE $record; $record_count++; } # while loop close (FILE); print "...$record_count records generated and stored in file $sample_data_file\n\n";