On Thu, Nov 14, 2002 at 05:38:19PM +0000, Nick Ing-Simmons wrote:
> ExtUtils::Command was my scheme to get rid of some long complex invokations
> in the Makefiles.
Different problem. In this case the problem is not with the code, but with
the data. And not with perl but with shell.
Consider this simple Makefile.
DATA = foo " bar ' yar
show_data :
perl -le 'print qq{$(DATA)}'
obviously, that perl command will vomit because of the quotes in $(DATA)
$ make show_data
perl -le 'print qq{foo " bar ' yar}'
/bin/sh: -c: line 1: unexpected EOF while looking for matching `''
/bin/sh: -c: line 2: syntax error: unexpected end of file
make: *** [show_data] Error 2
Ok, so how about putting it outside the perl code and read it as an
argument?
DATA = foo " bar ' yar
show_data :
perl -le 'print join "", @ARGV' $(DATA)
$ make show_data
perl -le 'print join "", @ARGV' foo " bar ' yar
/bin/sh: -c: line 1: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 2: syntax error: unexpected end of file
make: *** [show_data] Error 2
The problem is not perl quoting its shell quoting. I can't write a command
which can echo an arbitrary piece of data without first shell escaping that
data. It never even gets to perl. The data must first be escaped before
being passed to the shell.
Here's an option I'm trying to find something wrong with:
- Escape all the data when you generate the macro
So that would be something like:
DATA = foo '"' bar "'" yar
show_data :
perl -le 'print q{$(DATA)}'
and that works:
$ make show_data
perl -le 'print q{foo '"' bar "'" yar}'
foo ' bar " yar
but then you lose the whitespace if you decide to pass it in as an argument:
DATA = foo '"' bar "'" yar
show_data :
perl -le 'print join "", @ARGV' $(DATA)
$ make show_data
perl -le 'print join "", @ARGV' foo '"' bar "'" yar
foo"bar'yar
I'm not too up on shell escaping tricks. Can anyone construct an escaping
algorithm which causes both of the above show_data commands to come out the
same? If so, I think that'll solve the problem.
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
Here's hoping you don't harbor a death wish!