I have the following code that picks up zz.txt and when it comes to destination, it should be copied as zz_hostname.txt and instead it copies as zz_hostname?.txt. No idea how to get rid of that extra '?'.

#!/usr/bin/perl use strict; use warnings; my @array=(); my $diff_file="/tmp/diff.txt"; while (<STDIN>) { last if ($_ =~ /^\s*$/); # Exit if it was just spaces (or just + an enter) print "You typed: $_"; push @array,$_; } print "\@array = @array\n"; foreach my $i (@array) { #print $i system('/usr/bin/scp', "user\@$i:/tmp/zz.txt", "/tmp/zz_$i\.txt"); } foreach my $i (@array) { system('diff /tmp/zz.txt /tmp/zz_$i\.txt |tee -a $diff_file'); }

When it does the scp, it would create files like - zz_host1?.txt, zz_host2?.txt. .. Dont know where that extra '?' is coming from. Eventually, the diff also fails. The goal is to gather the diffs for a given file, across 10 hosts. The email should give the diff per host basis but one email should contain all the diffs.

First, how do I avoid that extra ? after scp ing the file. I played with escape chars but could not go ahead. thanks


In reply to scp command in perl introduces extra character while copying by surajsam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.