Greetings Monks, long time listener.....first time caller

I am attempting to accomplish something that I'm sure is probably dumb but I'm a hack (I admit it freely) and trying to deal with some ingested binary data in a way that makes sense in my brain (likely root of problem). I am ingesting binary output to stdout from a command run previous to the below code. Everything works as expected in the below code EXCEPT when I need to compare the value of previously defined variable (eg: $blu) by calling it in a foreach later where the string "blu" is an element and I try to call $blu by calling its element value in the foreach loop ${"index"} when $index equals blu, red, etc.

No matter what I try...${index}, ${'index'}, ${"index"} I can never draw in the value of $blu, $red, $grn or $ylw to evaluate whether or not it equals the value 01.

Thanks to all who take a moment to consider my quandary. Like I said I'm a hack and I'm beating my head against the desk.

{ chomp; my $dataout = $_; my @bytes = unpack( 'x252' . 'H2' x200, $dataout); my ($blu, $red, $grn, $ylw) = (@bytes[0], @bytes[12], @by +tes[56], @bytes[120]); my %humanize = ( 'blu' => 'Blue', 'red' => 'Red', 'grn' => 'Green', 'ylw' => 'Yellow' ); foreach my $index (blu, red, grn, ylw) { if (${"index"} != 01) { syslog('warning', "Color val +ue bad $humanize{$index}"); $status_code = 1; } } }

In reply to Calling a variable value as a variable by echo5

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.