in reply to passing delimiters on command line

If you trust the user,
$" = eval '"' . $delim . '"'; works.
Use eval with extreme caution, for security reasons.

You could parse it yourself:
%lookup_slash = ( t => "\t", n => "\n", ... );
$delim =~ s/\\(.)/$lookup_slash{$1}/ge;

But do you really expect slashed delimiters other than "\t"? If not, the previous snippet can be simplified to:
$delim =~ s/\\t/\t/g;

Or you could go fancier args...

Replies are listed 'Best First'.
Re^2: passing delimiters on command line
by Anonymous Monk on Sep 13, 2004 at 16:01 UTC
    The basic problem with  $" = eval '"' . $delim . '"' is that someone can pass something like  `rm -rf /` as the delimiter argument to your script. A QND workaround would be to just reject anything over two characters in length for the delimiter argument... like so:
    die "some trouble is brewing\n" if length($ARGV[0]) > 2; # Freely borrowed from ikegami $delim = eval '"' . $ARGV[0] . '"'; print "Field1" . $delim . "Field2" . $delim . "Field3" . $/;
    Good luck