in reply to Using Variables in Path Names
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+)/;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Using Variables in Path Names
by dvergin (Monsignor) on Nov 28, 2001 at 03:51 UTC | |
by jeroenes (Priest) on Nov 28, 2001 at 16:06 UTC | |
by dragonchild (Archbishop) on Nov 28, 2001 at 19:09 UTC | |
by IlyaM (Parson) on Nov 28, 2001 at 21:07 UTC | |
by tadman (Prior) on Nov 28, 2001 at 20:48 UTC | |
by impossiblerobot (Deacon) on Nov 28, 2001 at 21:25 UTC | |
Re: Re: Using Variables in Path Names
by andye (Curate) on Nov 28, 2001 at 15:46 UTC |