Skip to content

Commit

Permalink
refined the code
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeMagiera committed Oct 30, 2020
1 parent c603d20 commit 9cfd738
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions prod/prod-app/cgi-bin/data_collector.cgi
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/perl -ws
# This cgi script parses the submission.

# Read the DATA_DIR environment variable to construct the path for data files to be written to.
$datadir = $ENV{'DATA_DIR'};
# This cgi script parses Experience Sampler submissions and writes the resulting key/value pairs into a data file for each.

# Get the request method.
$request_method = $ENV{'REQUEST_METHOD'};
Expand Down Expand Up @@ -48,10 +45,15 @@ print "Content-type: text/html", "\n\n";
print $response_content;

# Construct the data file name.
my $filename = "participant_${id}_data.csv";
$filename = "participant_${id}_data.csv";

# Check for the DATA_DIR environment variable. If it exists, use it to construct a full path for data files to be written to. Otherwise, the files are written to the same folder as the script.

# Construct the data file path.
my $filepath = $datadir . "/" . $filename;
if(defined $ENV{'DATA_DIR'}) {
$filepath = $ENV{'DATA_DIR'} . "/" . $filename;
} else {
$filepath = $filename;
}

# Open a file handle to write the data.
open( OUTFILE, ">>", $filepath) or die $!, "Couldn\'t open outfile for writing!\n";
Expand Down

0 comments on commit 9cfd738

Please sign in to comment.