Now, consider constructing a path from variables, such as you are trying to do. Instead of using string interpolation, such as "$HOME/$x/$y", you should just join:#!/usr/local/bin/perl -wT use strict; use CGI; my $q = CGI->new(); print $q->header(); # Using CGI is even easier than doing it yourself, # so PLEASE(!) use it! $studentid = $q->param('studentid'); $CSC = $q->param('CSC'); chomp($CSC); $assignment = $q->param('assignment'); $file = $q->param('file');
Of course, before you even think of doing this, you must validate your parameters to make sure they are "kosher". Using 'perl' with the '-T' parameter makes user data tainted, or icky, and your program will fail with errors unless you check them out first.my $path = join ('/', $HOME, 'classes', $CSC, $studentid, $assignment, 'outputfile.txt');
You should define your input specification as narrow as possible. For example, if you just wanted numbers, you can use '\d+'. If none of this makes any sense, a quick browse through the regular expressions reference will help immensely. This is time well spent.# An example of "validated" input my ($studentid) = $q->param('studentid') =~ /(\w+)/;
In reply to Re: Using Variables in Path Names
by tadman
in thread Using Variables in Path Names
by lfindle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |