For the first chuck of code, I think it works better if you don't use comma in qw() and the DBG variables need to have a $ in front.

Here are the changes that I made to the first chunk code and the output.

bruce:1:~/tmp $ cat p.pl #!/usr/bin/env perl use strict; use warnings; use Readonly; my @EXPORTs = qw(DBG_ONE DBG_TWO DBG_FOUR) ; Readonly my $DBG_ONE => 1; Readonly my $DBG_TWO => 2; Readonly my $DBG_FOUR => 4; no strict 'refs'; foreach my $flag (@EXPORTs) { printf "flag = %s, value = 0x%04x\n", $flag, ${$flag}; } bruce:1:~/tmp $ ./p.pl Use of uninitialized value in printf at ./p.pl line 15. flag = DBG_ONE, value = 0x0000 Use of uninitialized value in printf at ./p.pl line 15. flag = DBG_TWO, value = 0x0000 Use of uninitialized value in printf at ./p.pl line 15. flag = DBG_FOUR, value = 0x0000

In pondering why the uninitialized value warnings were being displayed I remembered that you can't use symbolic references on my variables. So change the my to our and retry ...

#!/usr/bin/env perl use strict; use warnings; use Readonly; my @EXPORTs = qw(DBG_ONE DBG_TWO DBG_FOUR) ; Readonly our $DBG_ONE => 1; Readonly our $DBG_TWO => 2; Readonly our $DBG_FOUR => 4; no strict 'refs'; foreach my $flag (@EXPORTs) { printf "flag = %s, value = 0x%04x\n", $flag, ${$flag}; } bruce:1:~/tmp $ ./p.pl flag = DBG_ONE, value = 0x0001 flag = DBG_TWO, value = 0x0002 flag = DBG_FOUR, value = 0x0004

Much better.


In reply to Re: indirect/symbolic access in perl by bruceb3
in thread indirect/symbolic access in perl by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.