我被困在Learning Perl第6版的第4章练习4第78页.我从第301页复制了问题的代码示例.我在Ubuntu 11.04上使用Perl版本5.10.1.我得到的错误,我无法弄清楚有人可以帮忙吗?我将列出下面的代码和错误消息.
#!/usr/bin/perl -w
use strict;
greet( 'Fred' );
greet( 'Barney' );
sub greet {
state $last_person;
my $name = shift;
print "Hi $name! ";
if( defined $last_person ) {
print "$last_person is also here!\n";
}
else {
print "You are the first one here!\n";
}
$last_person = $name;
}
Global symbol "$last_person" requires explicit package name at ./ex4-4 line 8.
Global symbol "$last_person" requires explicit package name at ./ex4-4 line 14.
Global symbol "$last_person" requires explicit package name …Run Code Online (Sandbox Code Playgroud) 我被困在Learning Perl第6版的第2章练习2第42页.我从第296页复制了问题的代码示例.我在Ubuntu 11.04上使用Perl版本5.10.1.我得到的错误,我无法弄清楚有人可以帮忙吗?我将列出下面的代码和错误消息.
#!/usr/bin/perl -w
$pi = 3.141592654;
print "What is the radius? ";
chomp($radius = <STDIN>);
$circ = 2 * $pi * $radius;
print "The circumference of a circle of radius $radius is $circ.\n";
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
./ex2-2: line 3: =: command not found
Warning: unknown mime-type for "What is the radius? " -- using "application/octet-stream"
Error: no such file "What is the radius? "
./ex2-2: line 5: syntax error near unexpected token `$radius'
./ex2-2: line 5: `chomp($radius = <STDIN>);'
Run Code Online (Sandbox Code Playgroud) perl ×2