The shell's most likely your problem here, not Perl. Perl won't look at the contents of $filename if you interpolate it into a string, but the resulting string will be seen by a shell which will happily interpret $var if you're not careful.
The following works for me:
#!/usr/bin/perl use strict; use warnings; my $filename = q{$vaa it's not.txt}; $file =~ s/\$/\\\$/; my $exec = `touch "$filename"`;
The double quotes (in the `` string) are passed to the shell there, and ensure that the spaces in $filename won't be an issue. The regular expression adds a backslash in front of the dollar sign; this keeps it from being interpreted by the shell. Finally, the single quote in the filename is not considered special by either Perl or the shell.
In reply to Re: quoting/escaping file names
by AppleFritter
in thread quoting/escaping file names
by famatte
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |