Thread aus hashreferenz -> hashnamen ermitteln (20 answers)
Opened by worst_case at 2019-01-27 16:55

haj
 2019-01-27 17:46
#189637 #189637
User since
2015-01-07
521 Artikel
BenutzerIn

user image
Ohne Buddeln (mit CPAN:PadWalker) geht das nicht.

Zwei Dinge gehen dagegen ganz einfach:
  • Eine "Identifikation" des Hash bekommst Du mit print $ref;. Da bekommst Du einen String wie HASH(0x55972de08c28).
  • Du kannst als Konvention Deinem Hash einen Namens-Key mitgeben:
    Code (perl): (dl )
    1
    2
    3
    4
    5
    6
    7
    8
    
    my %haha = (__name => 'Mein Name ist Hash');
    
    test(\%haha);
    
    sub test {
       my ($ref) = @_; # Die Klammern sind notwendig!
       print $ref->{__name}; # Mein Name ist Hash
    }

View full thread aus hashreferenz -> hashnamen ermitteln