例:
my $some_variable;
my @some_variable;
my %some_variable;
Run Code Online (Sandbox Code Playgroud)
我知道,@
似乎是为了数组,$
对于原始,它是完全正确的吗?什么是%
?
据我所知,创建类(包)的动态实例就像是对Perl语法的破解(使用'bless').Perl不支持名为"class"的关键字; 因此一切都是有限的.
在创建静态类属性和静态类方法时,导致OOP困难的Perl的第一个限制.有解决方案吗
可能重复:
1是什么; Perl意味着什么?
我是Perl的新手,学习如何用Perl构建一个类.
从这个例子开始:http:
//www.tutorialspoint.com/perl/perl_oo_perl.htm,我看到一行写成"1;" 只是找不到有关这条有趣线路的信息perldoc.perl.org
你知道这是什么吗?为什么它在Perl源代码中?
还行吧:
if ($some_var==$some_value) {}
Run Code Online (Sandbox Code Playgroud)
这也没问题:
print "hello" if ($some_var==$some_value);
Run Code Online (Sandbox Code Playgroud)
但这会引发错误:
if ($some_var==$some_value) print "some_message";
Run Code Online (Sandbox Code Playgroud)
为什么Perl中的'if'子句必须带有大括号或什么都没有?
我有一个Perl类文件(包):person.pl
package person;
sub create {
my $this = {
name => undef,
email => undef
}
bless $this;
return $this;
}
1;
Run Code Online (Sandbox Code Playgroud)
我需要在另一个文件中使用这个类:test.pl
(请注意,person.pl和test.pl位于同一目录中)
require "person.pl";
$john_doe = person::create();
$john_doe->{name} = "John Doe";
$john_doe->{email} = "johndoe@example.com";
Run Code Online (Sandbox Code Playgroud)
但它没有取得成功.
我正在使用XAMPP来运行PHP和Perl.
我认为使用"require"获取类'person'的代码似乎不对,但我不知道如何解决这个问题.请帮忙...
perl ×5
syntax ×4
class ×3
oop ×3
declaration ×1
if-statement ×1
include ×1
package ×1
require ×1
static ×1