Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: File::Copy - not working!

by helgi (Hermit)
on Jun 19, 2003 at 12:57 UTC ( #267166=note: print w/replies, xml ) Need Help??

in reply to File::Copy - not working!

1 - As the others have said, you are not using File::Copy at all, so your subject heading is wrong.

2 - No warnings or strictures.

3 - As the others have said, you should use File::Basename to get the file basename, not this kludgery.

4 - System commands return errors, but you're not even looking at it. Errors from daughter processes are in the variable $?. Use it.
system("cp $tmpfile $copypath/$att_file") == 0 or die "Cannot copy $tmpfile to $copypath:$?\n";

5 - How can we know if $tmpfile has a value? You don't show us the tmpFileName subroutine code nor what is contained in the $clientattachment variable.

6- If I try $tmpfile = tmpFileName($clientattachment) || die("Failed");, it always dies. .
It does? Do you even have a tmpFileName sub?

Helgi Briem
helgi DOT briem AT decode DOT is

Replies are listed 'Best First'.
Re: Re: File::Copy - not working!
by bodmin (Acolyte) on Jun 19, 2003 at 13:46 UTC

    What syntax would I use if I were to use File::Basename?

    I presumed that tmpFileName() was a function in File::Copy. Was obviously mistaken.

    Thanks for the advice and comments.

      Since your incoming path seems to have Windows type backslashes as delimiters, I am using that below.

      However, you should always use forward slashe, even under Windows, and get rid of them as soon as possible with something like: $path =~ s.\\.\/.g;

      use warnings; use strict; use File::Basename; my $path_to_file = 'bla\bla\full\path\to\file.ext'; $path_to_file =~ s.\\.\/.g; my ($file,$path) = fileparse($path_to_file); print "$file is in $path\n";

      For copying files using File::Copy, you do:

      use File::Copy; copy $file,$newpath or die "Cannot copy $file to $newpath:$!\n";

      Helgi Briem
      helgi DOT briem AT decode DOT is

        I tried the above and it did not work as expected, or shall I say at all.

        my $path_to_file is a file form field on a web page being displayed on a windows client, hence c:\...... do you think that is why it does not work? Is your $path_to_file on the same machine (in my case the linux web server)?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://267166]
[karlgoethebier]: The early bird catches the worm
holli enters he monastery hall, freezing but happy to have built the most beautiful snowman in the history of mankind
[holli]: tbh, the thing looks more like quasimode but hey, the thought matters. and it has blue LEDs as eyes

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-12-18 05:49 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (467 votes). Check out past polls.