perl join on a non printable variable character ?

B

Brian McCauley

The delimiter needs to be converted before use. If you don't mind
cheating, you could do this:

$delimiter = eval("\"$delimiter\"");

(Mumia ducks)

Wise :)
Okay, sorry about that. "Eval" is evil I know. You could also do this:

$delimiter =~ s/^\\//;
$delimiter = chr oct $delimiter;

However, that can't deal with delimiters specified in hex on the command
line.

The solution I posted (Sat, 06 Oct 2007 17:46:15 -0000) covers all
possibilities but I'm not 100% convinced that my escaping of ["$@]
characters would be sufficient to prevent a determined attacker from
exploiting the eval.
 
M

Mumia W.

[...]
The solution I posted (Sat, 06 Oct 2007 17:46:15 -0000) covers all
possibilities but I'm not 100% convinced that my escaping of ["$@]
characters would be sufficient to prevent a determined attacker from
exploiting the eval.

Okay, now I see it. I somehow missed that message before.

I'm tempted to add this alternative:

die "bad delimiter = '$delimiter'" unless
($delimiter =~ /\A(\\\d+|0x\d+|\d+|\\X{\d+})\z/);
$delimiter = eval qq{"$delimiter"};

However, Jack can probably adjust his requirements to not require the eval:

perl e:\add_uniquekeyfield.pl e:\tmp\file1.txt e:\tmp\file2.txt 034

Then all he needs is this:

my ($filename1, $filename2, $delimiter) = @ARGV;
$delimiter = chr oct $delimiter;

__ONLY_PARTIALLY_TESTED__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top