in reply to backticks execution "inside" variable (string)
eval'ing user-supplied string (the filename) within perl is not only dangerous as others said but it is a practice frowned upon and you will be told off (even if it is innocent) if this is at work.
I would use a function to parse the user-input/filename and recognise a *few* things that may be useful in a log filename. For example date:
#!/usr/bin/perl use strict; use warnings; use Time::Piece; my $newfilename = userinput2filename($ARGV[0]); print "got this: $newfilename\n"; sub userinput2filename { my $inp = $_[0]; my $out = $inp; while( $out =~ s/`(.+?)`/_userinput2filename($1)/eg ){} return $out } sub _userinput2filename { my $inp = $_[0]; # date +FORMAT where FORMAT must be understood by POSIX's strftime if( $inp =~ /^date\s+\+(.+?)$/ ){ return Time::Piece->new()->strftim +e($1) } # insert other cases you want to substitute # eventually there is something in backticks that is not in our list die "do not understand '$inp'" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: backticks execution "inside" variable (string)
by richard.sharpe (Sexton) on Dec 20, 2019 at 14:34 UTC | |
by bliako (Abbot) on Dec 20, 2019 at 17:45 UTC |