0

我试过使用:

my $nomIHMBloc = $1;
print decode_entities($nomIHMBloc), "\n";
$nomIHMBloc = decode_entities($nomIHMBloc), "\n";

但没有运气。有什么问题吗?我收到错误:

Undefined subroutine &main::decode_entities called at "same perl file"

谢谢你的帮助。

PS:确切的代码在这里:

    while($blocVars =~ m/\[(.*?)\]/g){
                binmode STDOUT, ':utf8';
                my $nomIHMBloc = $1;
                print decode_entities($nomIHMBloc), "\n";
                $nomIHMBloc = decode_entities($nomIHMBloc);
                print "nomIHMBloc::::::::$nomIHMBloc=============$1\n";
                print "insert into ASSOC_VAR_BLOC (ID_BLOC, ID_VAR, DOC_ID_MAQUETTAGE) VALUES ($id_bloc, (SELECT ID_VAR FROM VARIABLE WHERE NOM_IHM='$nomIHMBloc'),'$docId')\n";
    }
4

1 回答 1

2

在这里工作正常:

#!/usr/bin/env perl

use strict;
use warnings;
use open ':locale';
use HTML::Entities;

# example text
'42°' =~ /(.*)/; # 42°

# your code
my $nomIHMBloc = $1;
print decode_entities($nomIHMBloc), "\n";
#$nomIHMBloc = decode_entities($nomIHMBloc), "\n";

您的最后一行包含语法错误。如果要在分配给标量时添加换行符,请使用字符串连接运算符.

$nomIHMBloc = decode_entities($nomIHMBloc) . "\n";

它之所以有效,print是因为它是一个列表运算符并接受一个参数列表,然后将它们与输出字段分隔符 $,(请参阅perlvar)连接起来,该分隔符默认包含空字符串,并且充当简单的字符串连接。但是,输出是

42°

于 2012-11-28T16:58:30.877 回答