4

サンプルコードを検討してください:

$VAR1 = {
      'en' => {
              'new' => {
                       'style' => 'defaultCaption',
                       'tts:fontStyle' => 'bold',
                       'id' => 'new'
                     },
              'defaultCaption' => {
                                  'tts:textAlign' => 'left',
                                  'tts:fontWeight' => 'normal',
                                  'tts:color' => 'white',

                                }
            },
      'es' => {
              'defaultSpeaker' => {
                                  'tts:textAlign' => 'left',
                                  'tts:fontWeight' => 'normal',

                                },
              'new' => {
                       'style' => 'defaultCaption',
                       'tts:fontStyle' => 'bold',
                       'id' => 'new'
                     },
              'defaultCaption' => {
                                  'tts:textAlign' => 'left',
                                  'tts:fontWeight' => 'normal',

                                }
            }
    };

私はそれを参照として返し、\%hash を返します

これを逆参照するにはどうすればよいですか?

4

2 に答える 2

8

%$hash. 詳細については、 http://perldoc.perl.org/perlreftut.htmlを参照してください。

関数呼び出しによってハッシュが返された場合は、次のいずれかを実行できます。

my $hash_ref = function_call();
for my $key (keys %$hashref) { ...  # etc: use %$hashref to dereference

または:

my %hash = %{ function_call() };   # dereference immediately

ハッシュ内の値にアクセスするには、->演算子を使用できます。

$hash->{en};  # returns hashref { new => { ... }. defaultCaption => { ... } }
$hash->{en}->{new};     # returns hashref { style => '...', ... }
$hash->{en}{new};       # shorthand for above
%{ $hash->{en}{new} };  # dereference
$hash->{en}{new}{style};  # returns 'defaultCaption' as string
于 2013-05-15T07:11:56.650 に答える