我有一个脚本,它接受一个字符串并在字符串末尾放置一个“.html”。 如果字符串已经有“.hmtl”,我想删除它,然后添加 html 它工作正常,但我收到警告并且不理解该警告。
#!/usr/bin/perl
use strict;
use warnings;
# Check if a string is provided as an argument
if (@ARGV != 1) {
die "Usage: $0 'string'\n";
}
# Get the input string from the command line arguments
my $input = $ARGV[0];
if ($input =~ s/\.html$//) {
$input ;
}
# Convert all characters to lowercase
$input = lc($input);
# Replace spaces with underscores
$input =~ s/ /_/g;
# Print the modified string
print "<!--- \"$input.html\" -->\n";
print " \n";
print " \n";
print "$input.html"
我收到此警告
Useless use of private variable in void context at
./perl_make_html_string_cut_html.pl line 14.
就是这一部分:
if ($input =~ s/\.html$//) {
$input ; # <----- error line
}
也许您想在那里放一条打印语句?到目前为止,它只是 void 上下文中的一个变量,就像错误所说的那样。
如果您有显示行号的文本编辑器,您可以自己查看哪一行报告了错误。