S
S
script882012-07-09 13:59:18
Perl
script88, 2012-07-09 13:59:18

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";

After launching and entering data, info is written to the log,
when viewed, it is clear that after each input a carriage return occurs:

sh: line 1: .09-07-2012-14.56: command not found
sh: line 2: .txt: command not found

How to avoid it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
kafeman, 2012-07-09
@script88

chomp() ?

B
Bambre, 2012-07-11
@Bambre

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,

I
Ivan Komarov, 2012-07-09
@FreeTibet

chomp($var = );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question