Perlでプログラムを実行する際に問題が発生しました。

Perlでプログラムを実行する際に問題が発生しました。
#!/usr/bin/perl
#Script:name2.pl - Demonstrates use of chop
#
print("Enter your name:");
$name=<STDIN>;
$lname = chop($name);                      #Removes newline character from $name
if ($lname ne "") {
   print("$lname,have a nice day\n");
 } else {
 print("You have not entered your name\n");
}
$ ./name2.pl
Enter your name:stallman

,have a nice day
$

Perlプログラムが実行されたときに「chop」機能を実行しません。

プログラミング回路にエラーがありますか?

ベストアンサー1

バラよりマグカット

文字列の最後の文字をトリップし、切り捨てられた文字を返します。

つまり、文字列をローカルに変更します。

「切り捨てられた文字列」を返すとします。

#!/usr/bin/perl -w

my $x = "Turing, Alana";

my $r = chop($x);

print "\$x is now '$x', and \$r is now '$r'\n";

それから:

$x is now 'Turing, Alan', and $r is now 'a'

おすすめ記事