echo5 has asked for the wisdom of the Perl Monks concerning the following question:
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; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling a variable value as a variable
by jwkrahn (Abbot) on Dec 12, 2018 at 04:46 UTC | |
|
Re: Calling a variable value as a variable
by eyepopslikeamosquito (Archbishop) on Dec 12, 2018 at 08:00 UTC | |
|
Re: Calling a variable value as a variable
by Marshall (Canon) on Dec 12, 2018 at 07:56 UTC | |
|
Re: Calling a variable value as a variable
by davido (Cardinal) on Dec 13, 2018 at 00:13 UTC |