Answer the question
In order to leave comments, you need to log in
Perl developers help with script
The script itself
#!/usr/bin/perl
print "Host: ";
$DBhost = <STDIN>;
print "User: ";
$DBuser = <STDIN>;
print "Pass: ";
$DBpass = <STDIN>;
print "DBname: ";
$DBname = <STDIN>;
$Date = `date +%d-%m-%Y-%H.%M`;
$log = "Backup.'$DBname'.'$Date'.txt";
system "echo '$log' > temp.log";
Answer the question
In order to leave comments, you need to log in
Tell me, why the hell do you need a pearl if you write on it like on a head?
$Date = `date +%d-%m-%Y-%H.%M`;
use POSIX 'strftime';
$Date = strftime('%d-%m-%Y-%H.%M', localtime);
$log = "Backup.'$DBname'.'$Date'.txt";
You can use the advice above about chomp, it's more correct. Or you can cut out all newlines already from the collected $log variable, in this case it's a little shorter:
$log =~ s/[\r\n]//g;
system "echo '$log' > temp.log";
open my $fd, ">", "temp.log" or die "Can't open temp.log: $!";
print $fd $log;
close $fd;
Yes, it is clearly longer, but also much more efficient. Fork the process to find out the date or write a line to a file,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question