Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Am Trying to copy a pdf file to the server.
open(NEW, ">c:\\temp.pdf")) my $buffer; binmode NEW; # start reading users HD 1 kb at a time. $file="c:\\temp1.pdf" while(read($file, $buffer, 1024)) { print NEW $buffer; } close NEW;

The file is not read. Thanks in advance,
Shiva

Replies are listed 'Best First'.
Re: reading files in binary mode
by BrowserUk (Patriarch) on Dec 21, 2005 at 15:00 UTC

    Take a look at the arguments for read. It takes a filehandle as the first argument, not a filename. You need to open the input file as well as the output file.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: reading files in binary mode
by ptum (Priest) on Dec 21, 2005 at 15:09 UTC

    And of course, you should always check the success of a file operation. If I had a nickel for every time that saved me, I'd, er, have a lot of nickels. :)

    Update: Ah, I see that [id://Hue-Bond] checks for the success of open in his example.


    No good deed goes unpunished. -- (attributed to) Oscar Wilde
Re: reading files in binary mode
by wolfger (Deacon) on Dec 21, 2005 at 15:05 UTC
Re: reading files in binary mode
by Hue-Bond (Priest) on Dec 21, 2005 at 15:07 UTC
    $ md5sum f1 f2 5b683521f9b6b4126005fffdca888ec2 f1 md5sum: f2: No existe el fichero o el directorio $ perl open my $in, '<', 'f1' or die "open1: $!"; open my $out, '>', 'f2' or die "open2: $!"; binmode $in; binmode $out; { my $buf; print $out $buf while read $in, $buf, 1024; } close $out; close $in; __END__ $ md5sum f1 f2 5b683521f9b6b4126005fffdca888ec2 f1 5b683521f9b6b4126005fffdca888ec2 f2 $ _

    Update: Had forgotten binmode.

    --
    David Serrano

Re: reading files in binary mode
by swampyankee (Parson) on Dec 21, 2005 at 17:16 UTC

    This may be a spectacularly silly question, but why are you using Perl to copy a file? Usually, the O/S has facilities for this sort of thing.