我如何祝福 Perl 中的字符串?
我试图祝福一个字符串变量——如下面的代码所示。 Bless 似乎只在我使用哈希或数组时才起作用。你可以祝福琴弦吗?如果没有,你能祝福什么?我已经调试了一段时间,任何帮助将不胜感激。 :-) 如果我在代码中犯了错误,请告诉我它是什么。
这是一个 perl 文件。代码尚未完成,但它从未到达“Page End”语句。所以我不再延长它了。 $FileInfo 是之前从文件中读取的数组定义,但由于语法原因,此处出现乱码。
这是构建对象引用的调用
$page = new GeneratePages(0);
package GeneratePages;
sub new
{
my $class = shift;
my $pageContents = $FileInfo[shift];
bless $pageContents, $class;
return $pageContents;
}
I am trying to bless a string variable -- demonstrated in the code below. Bless only seems to work when I use a hash or array. Are you allowed to bless strings? If no, what can you bless? I have been debugging for a while, any help would be greatly appreciated. :-) If I making an error in my code please let me know what it is.
This is a perl file. The code is not finished, but it never reaches the "Page End" statement. So I have ceased to lengthen it. $FileInfo is an array define earlier read from a file but due to syntax gets garbled here.
here is the call to build ojbect reference
$page = new GeneratePages(0);
package GeneratePages;
sub new
{
my $class = shift;
my $pageContents = $FileInfo[shift];
bless $pageContents, $class;
return $pageContents;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Bless 仅适用于引用。来自 perldoc bless:
因此,如果您想使用字符串作为对象,您应该将对其的引用传递给
bless
:Bless only works on references. From perldoc bless:
So if you want to use a string as an object, you should pass a reference to it to
bless
: