Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problems with File Copy

martin23martin23 Posts: 6Member
hi I have a problem with the following script:-

#!/usr/bin/perl -w
use strict;
use warnings;
use File::Copy;
my $file = 'm:serverlist1.txt';
open (INFO, $file);
while ($file = )
{

#chomp $file;
#print $file;
copy("m:\robcop\screenshots1.doc","$file")or die "Copy failed: $!";
#print "copied to $file
";
}

it fails on path not found,
yet the list of paths
\\server1\userinfo\sfm\fact sheets\
\\server2\userinfo\sfm\fact sheets\
\\server3\userinfo\sfm\fact sheets\

is correct, and if I type one of these lines in in place of $file it works no problem.
Can anyone help

Comments

  • JonathanJonathan Posts: 2,914Member
    : hi I have a problem with the following script:-
    :
    : #!/usr/bin/perl -w
    : use strict;
    : use warnings;
    : use File::Copy;
    : my $file = 'm:serverlist1.txt';
    : open (INFO, $file);
    : while ($file = )
    : {
    :
    : #chomp $file;
    Keep the chomp. It's your friend.

    : #print $file;
    : copy("m:\robcop\screenshots1.doc","$file")or die "Copy failed: $!";
    : #print "copied to $file
    ";
    : }
    :
    : it fails on path not found,
    : yet the list of paths
    : \\server1\userinfo\sfm\fact sheets\
    : \\server2\userinfo\sfm\fact sheets\
    : \\server3\userinfo\sfm\fact sheets\
    :
    : is correct, and if I type one of these lines in in place of $file it works no problem.
    : Can anyone help
    :
    Is that list of paths stored in the file? If so, you don't need to escapse 's in files.

    \server1userinfosfmfact sheets
    \server2userinfosfmfact sheets
    \server3userinfosfmfact sheets

    You only need to do that in literals in your Perl script that are in interpolative context. By that I mean:-

    print "Escpae \ in double quotes";
    print 'No need to escape in single quotes';

    If you hava a variable inbetween double quotes it doesn't have to have the escaped data etc - it's only for data you have directly in your program. Hope that makes sense.

    Also, minor style point - you did "$file". For just one variable you can do away with the quotes, just write $file.

    Hope this helps,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.