Welcome to WebmasterWorld Guest from 23.23.53.177

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

move file to other directory?

   
2:47 am on Mar 9, 2004 (gmt 0)

10+ Year Member



hi

I wrote this perl sript and it should move the file
to the other directory after the mail was sent.

I get this error message:

"Useless use of string in void context at mail.cgi line 75.
Can't call method "move" without a package or object reference at mail.cgi line 75."

knows someone what's wrong and how to correct it?


#!/usr/bin/perl -w
use strict;
use warnings;
my $recipient = "recipient\@mydomain.net";
my $linux = "root\@mydomain.net";
my $file = "/var/tmp/file.txt";

# read the file
my $content;
open(FILE, $file) die "Cant open file. Reason: $!"; # (-:
while(<FILE>) {
$content .=$_; # get all of the file into content including past new lines
}
close(FILE);

# send the mail with file content
open(MAIL, "/usr/sbin/sendmail -t") die "Cant send mail. Reason: $!";
print MAIL "from:$linux\n";
print MAIL "to:$recipient\n";
print MAIL "subject:Hi!\n";
print MAIL "$content \n\n";
print MAIL "Time: ", scalar localtime, "\n";
close(MAIL);

#move file to the new directory and remove it at the old location
move $file, "/var/backup";
exit;

8:55 am on Mar 9, 2004 (gmt 0)

10+ Year Member



The correct syntax for renaming or moving a file to another location is:
mv $file1 $file2

So I suggest you replace this line:

move $file, "/var/backup";

with this:

system("mv $file /var/backup/$file");

Also: don't forget to include the correct path to $file.

9:39 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



thanks!

it works well now.