#!/usr/bin/perl

# Specify the special folder from which all files will be drawn.
$restricted_folder = ".";

# Get a base file name from the user. No input validation! Bad!
$base_name = <STDIN>;
# Match against a regular expression to "de-taint" the input.
#$base_name =~ /^([a-zA-Z.]+)$/ or die $1;
#$base_name = $1;

print "Base file name: ", $base_name, "\n";

# Try reading from the input file.
$input_file = $restricted_folder . "/i" . $base_name;
open(INPUT, "<$input_file") or die $!;
print <INPUT>;

# Try writing to the output file.
$output_file = $restricted_folder . "/o" . $base_name;
open(OUTPUT, ">$output_file") or die $1;
print OUTPUT "This line was produced by the script.";
