admin@myServ> ./test.sh
#!/bin/bash
# USAGE :
# "./change_date.sh 24" : 24/09/2014
# "./change_date.sh 25" : 25/09/2014
# "./change_date.sh" : 24/09/2014
echo "Before : " $(date)
## BEGIN SERV ## (serv05 : serv05.company.org) ##
serv05 : myUser
root
#!/bin/bash
# USAGE :
# ./change_date.sh 24 : 24/09/2014
# ./change_date.sh 25 : 25/09/2014
# ./change_date.sh : 24/09/2014
echo Before : Thu Sep 25 12:59:13 CEST 2014
## END SERV ## (serv05 : serv05.company.org) ##
[...]
admin@myServ>
它正在运行,但我有错误。我该如何修复此错误?你能帮帮我吗?
此错误:
usrbin perl
#!/usr/bin/perl use strict; use warnings; my %count; my $file = "meme.txt" or die "KullanÄlÄyor: $0 FILE\n"; open my $fh, '<', $file or die "AÃÄlamadı '$file' $!"; while ( my $line = <$fh> ) { chomp $line; foreach my $str ( split /\s+/, $line ) { $count{$str}++; } } foreach my $str ( sort keys %count ) { if ( -e "/home/%-31s %s\n", $str, $count{$str} and -d "/home/%-31s %s\n", $str, $count{$str} ) { print "Varmış böyle dizin\n"; } else { print "Kapat kapat çok yazdı\n"; } }
答案 0 :(得分:1)
您正在构建一个可能应该是目录路径的字符串。这个字符串
"/home/%-31s %s\n"
最后有一个新行,你可能不打算
您的程序还存在许多其他问题,我建议应该更多地编写这个问题
#!/usr/bin/perl
use strict;
use warnings 'all';
my %count;
my $file = 'meme.txt';
{
open my $fh, '<', $file or die "AÃÄlamadı '$file': $!";
while ( <$fh> ) {
++$count{$_} for split;
}
}
for my $str ( sort keys %count ) {
my $dir = sprintf '/home/%-31s %s', $str, $count{$str};
if ( -d $dir ) {
print "Varmış böyle dizin\n";
}
else {
print "Kapat kapat çok yazdı\n";
}
}
答案 1 :(得分:0)
当操作中出现任何错误并且文件名包含换行符&#34; / n&#34;时,显然会发生这种情况。要解决此问题,请通过chomp()运行文件名。这将删除换行符并应该停止错误。