[kw-pm] trying to diff two files which contain '$' in their names

Robert P. J. Day rpjday at crashcourse.ca
Wed Mar 16 03:41:38 PDT 2011


  a colleague presents me with the following (simple?) perl problem.
first, here's a variation of the program that works:

#!/usr/bin/perl

$f1 = 'file1';
$f2 = 'file2';

$res = `diff $f1 $f2`;
print $res, "\n";

  piece of cake -- there are two variables that contain the names of
perfectly respectable files, those files are diff'ed and the result of
the diff is saved and printed.

  the problem is that the filenames sometimes contain a literal dollar
sign as part of the name (don't ask).  so a simplified demo of the
problem would be:

#!/usr/bin/perl

$f1 = '$file1';
$f2 = '$file2';

$res = `diff $f1 $f2`;
print $res, "\n";

which gives me:

diff: missing operand after `diff'
diff: Try `diff --help' for more information.

  i've tried to backslash escape various things but no success.  what
bit of magic am i missing?

rday


More information about the kw-pm mailing list