in reply to How do I interpolate package name in a fully qualified name?

Using fields, I tried it without a foreach:
#!/usr/bin/perl use 5.012; use warnings; { package Example; use fields qw(Zelda Mario Kupa _Example_private); sub new { my Example $self = shift; unless (ref $self) { $self = fields::new($self); $self->{_Example_private} = "Inspection of Ex +ample"; } $self->{Zelda} = 'prince'; $self->{Mario} = 'hero'; $self->{Kupa} = 'villan'; return $self; } } package main; my $type = Example->new; print "Zelda is a ", $type->{Zelda}, "\n", "Mario is a ", $type->{Mario}, "\n", "Kupa is a ", $type->{Kupa}, "\n";

Replies are listed 'Best First'.
Re^2: How do I interpolate package name in a fully qualified name?
by AGhoulDoingPerl (Sexton) on Apr 22, 2011 at 14:52 UTC
    I'll try this when I need to ofuscate my code. :)
    Thank you for the answer.