Good day.

There is a sub'a, the first parameter to which the hash is transmitted, but not simple, but tricky. If you bring him through Dumper, then we see that he is inside bless (read, read, but did not understand how to practically understand it :)))

use Data::Dumper; sub test{ print Dumper shift } 

Conclusion

 $VAR1 = bless( { 'protocol' => 114, 'cb' => 'envrcpt', 'socket' => bless( \*Symbol::GEN2, 'IO::Socket::INET' ), 'callbacks' => { 'envrcpt' => sub { "DUMMY" } }, 'reply' => undef, 'callback_flags' => 31, 'symbols' => { 'M' => { '{auth_author}' => 'sender@domain.tld', '{mail_mailer}' => 'local' } } }, 'Sendmail:PMilter::Context' ); 

How to approach these fields? I would like to print var{'symbols'}{'M'}{'auth_author'} and get what we need.

  • "Perl |" - it is better to erase, I think this is not correct ... - Baran
  • what is this suddenly .. - Anton Shevtsov
  • Already fixed :). Because when you enter the question, the tag is substituted into the title and it turns out something like "perl - Perl | Reaching the hash element". - Baran

3 answers 3

It may be easier to use the ready Sendmail package : PMilter :: Context , there is a getsymval method. Napimer:

 use Sendmail:PMilter::Context; sub test { my $tx = shift; print $tx->getsymval('{auth_author}') } 

    A flashing hash is an object and for sure there are methods for working with its fields, it’s not very good to climb inside the hash of such a hash. But if you really want:

     my $sym = shift; warn $sym->{'symbols'}->{'M'}->{'{auth_author}'}; 
    • if you look at the dumper, you can see the contents, while the print ignores .. but you are right about the main thing, you shouldn’t go so far as to approach methods - Anton Shevtsov
     use Data::Dumper; sub test { my $t = shift; print $t->{protocol}; }