0

There is a newline character getting inserted between the 2 filenames. How do I avoid this?

$diff = `comm -3 "/tmp/${PATH1U}_${SITE1}_s_${USER} /tmp/${PATH2U}_${SITE2}_s_${USER}"|wc -l`;

This is the error message while executing:

comm: missing operand after `/tmp/file1\n /tmp/file2\n'

toolic
  • 57,801
  • 17
  • 75
  • 117
Glad
  • 321
  • 1
  • 4
  • 7

1 Answers1

4

Two problems:

  • $USER's value ends with a newline. You can chomp it away. Fix:

    chomp($USER);
    
  • You are passing one very long and incorrect path instead of two. Fix:

    `comm -3 '/tmp/${PATH1U}_${SITE1}_s_${USER}' '/tmp/${PATH2U}_${SITE2}_s_${USER}' | wc -l`
    

    But that's a hackish way of creating shell literals. Cleaner:

    use String::ShellQuote qw( shell_quote );
    
    my $comm_cmd = shell_quote('comm', '-3',
       "/tmp/${PATH1U}_${SITE1}_s_${USER}",
       "/tmp/${PATH2U}_${SITE2}_s_${USER}");
    
    `$comm_cmd | wc -l`
    
ikegami
  • 367,544
  • 15
  • 269
  • 518