I'm writing a script which reads data from a power meter. I've identified the wattage used by several devices and have a variable which identifies the wattage 'jump' when a device is turned on. I've declared each device wattage as a range and declared an array containing all device arrays as follows-
@device1 = (30..40);
@device2 = (50..70);
@device3 = (100..150);
@device_array1 = (\@device1, \@device2, \@device3);
The script reads the output from the meter and produces a $watts_jump variable. However I cant identify a working approach to match the variable against the @device_array1 and its 'sub' arrays.
Should I be doing a grep or be using List::Utils 'first' approach?
I've tried the following -
use List::Utils 'first';
my $device = first { /$watts_jump/ } @device_array1;
and as an alternative the grep for string method but neither find the match and report it back. If I print "$device_array1[1][2]\n"; or variation of - it does return the correct values.
If matched, I need what was matched and not its index e.g -
$watts_jump = 55 therefore $device = $device2
Any help or pointers to examples will be gratefully received. As you can probably tell this is my first attempt to do anything serious with perl and my first post here so be gentle. The first person to direct me to perldoc is off my xmas card list :-)
TIA