Export IVR data to CSV file

Hi Guys. I’m trying to make an script that create an CSV file, depending on what menu-options are entered in the phone menu.
For so far, it’s going kinda well except for the variables section, i’m not sure if there is a better way to do it than hope im doing it now. (well, actually i hope there is or i lose my confidence in perl :smile:
I’m no programmer, just used common sense to copy past some things into the script and trying to make it work.
Can you give me some help with this code, to make it a. more workable and b. more efficient. Maybe put it in an array or something? Also im not sure if the get_data function is properly used here…
Well here is my code, it asks the user his phone number, postalcode and housenumber, then askes if he wants all options blocked ($compleet) and if not, it askes 10 questions for a yes(1) or a no (0).
The final result is a daily CSV file with the pipe sign (|) as a seprator.

 #!/usr/bin/perl

use Asterisk::AGI;
use DBI;
use POSIX qw(strftime);
use Fcntl;

my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();

$datumnu = strftime("%d-%m-%Y %H:%M" , localtime);
$datum = strftime("%Y%m%d", localtime);

$filename = "/var/lib/asterisk/agi-bin/belmijniet/UPLOAD_$datum.txt";


if(-e $filename){
	open (CSV, ">>$filename");
} else {
	sysopen (CSV, $filename, O_RDWR|O_CREAT);
    }

$AGI->stream_file('custom/welkom');

$telefoonnummer = $AGI->get_data('custom/telefoonbericht',10000,10);
$postcode = $AGI->get_data('custom/postcodebericht',10000,4);
$huisnummer = $AGI->get_data('custom/huisnummerbericht',5000,3);
$compleet = $AGI->get_data('custom/compleetbericht',10000,1);
$AGI->verbose($compleet);

if($compleet = 1){
	$AGI->verbose("apply 1 to everything");
    
    $auto = 1;
    $boeken = 1;
    $energie =1;
    $financien = 1;
    $charit =1;
    $esoterie = 1;
    $kranten =1;
    $loterijen =1;
    $telecom = 1;
    $postorder = 1;
} else {
    $AGI->verbose("enter one-by-one");
    
    $auto = $AGI->get_data('beep',5000,1);
    $boeken = $AGI->get_data('beep',5000,1);
    $energie = $AGI->get_data('beep',5000,1);
    $financien = $AGI->get_data('beep',5000,1);
    $charit = $AGI->get_data('beep',5000,1);
    $esoterie = $AGI->get_data('beep',5000,1);
    $kranten = $AGI->get_data('beep',5000,1);
    $loterijen = $AGI->get_data('beep',5000,1);
    $telecom = $AGI->get_data('beep',5000,1);
    $postorder = $AGI->get_data('beep',5000,1);
}


if($telefoonnummer != ""){
    $AGI->verbose("$telefoonnummer|$postcode||$huisnummer|||||||||$datumnu|$auto|$boeken|$energie|$financien|$charit|$esoterie|$kranten|$loterijen|$telecom|$postorder\n");
    printf CSV "$telefoonnummer|$postcode||$huisnummer|||||||||$datumnu|$auto|$boeken|$energie|$financien|$charit|$esoterie|$kranten|$loterijen|$telecom|$postorder\n";
};


$AGI->verbose("End");
close (CSV);


$AGI->hangup(); 

Thanks in advance guys!

Bump! Anyone?

Last bump! i really need this :smiley: