in reply to perl unpack and matching the unpacked data
This would make your code twice shorter and probably a bit faster. You could also notice that $tid is "CEX" in most of the cases, so you could reorganize part of your tests:if ($data eq "8000" or $data eq 0080){ $tid = "TEST"; $buf = $test; } elsif ($data eq "8100" or $data eq "0081"){ $tid = "TOOL"; $buf = $tool; } elsif ...
There are other possible shortcuts, but using too many of them might lead to less clear code. But I think you should think of some basic ones at least. You could also "normalize" $data before testing, i.e. if $data is "00xx", change it to "xx00" and do your tests afterwards, that would also reduce your code by about half.$tid = "CEX" if grep {$_ eq $data} qw /8300 0083 ... 8F00 008F/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl unpack and matching the unpacked data
by james28909 (Deacon) on Jul 17, 2014 at 21:49 UTC | |
by AppleFritter (Vicar) on Jul 17, 2014 at 22:32 UTC | |
by AnomalousMonk (Archbishop) on Jul 17, 2014 at 22:34 UTC | |
by james28909 (Deacon) on Jul 17, 2014 at 23:50 UTC | |
by AnomalousMonk (Archbishop) on Jul 18, 2014 at 01:10 UTC | |
by Laurent_R (Canon) on Jul 18, 2014 at 06:24 UTC |