You can make your system
call a little safer.
There are two forms of system
. The string form gives system
one argument. The shell then interprets the string to figure out what to do. That might be something other than what you intend when you interpolate a variable. What is $var
is something like ; rm -rf
? That ;
ends the command and allows you to start a new one.
The list form is a bit safer. None of the arguments after the command are treated specially by the shell. If there's a shell metacharacter in $var
it's just it's literal self in this form:
system 'rsync', '-av', "$var/.*pl", '/scripts/';
Perl also has "taint-checking" that marks data that has come from outside your program (user input, files, whatever). Tainted data is viral; use it with untainted data and you get more tainted data. When you try to use tainted data to do something outside your program (like a system
), you get an error.
Check out perlsec. I also have a chapter on this in Mastering Perl. Good luck!