Perl hashes with an array of keys

前端 未结 1 1626
长情又很酷
长情又很酷 2021-01-22 02:00

Given an array which contains n elements (n more than 1), is there an elegant way to refer to the element in a hash structure where each element is the key in sequence?

相关标签:
1条回答
  • 2021-01-22 02:49

    That's why Data::Diver exists:

    #!/usr/bin/perl
    use warnings;
    use strict;
    
    use Data::Diver qw{ Dive };
    
    my $hash = { a => { b => { z => 'HERE' } } };
    
    my @foo = qw( a b z );
    
    print Dive($hash, @foo);
    
    0 讨论(0)
提交回复
热议问题