homepage Welcome to WebmasterWorld Guest from 23.22.59.252
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
move file to other directory?
cccc

10+ Year Member



 
Msg#: 3520 posted 2:47 am on Mar 9, 2004 (gmt 0)

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;

 

tombola

10+ Year Member



 
Msg#: 3520 posted 8:55 am on Mar 9, 2004 (gmt 0)

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.

cccc

10+ Year Member



 
Msg#: 3520 posted 9:39 pm on Mar 9, 2004 (gmt 0)

thanks!

it works well now.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved