haukex has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I'm looking for some module recommendations before I run off and reinvent a wheel. This is a two-part question; for the first part I haven't really found anything on CPAN, and for the second part I have a few ideas (below), but again, haven't really found anything. I suspect there might be some modules I'm missing.
So I have two-dimensional data represented as an AoA. In a configuration file, I need to specify ranges of that data, for example "extract rows X through Y and columns M through N". It would be nice if these ranges could be expressed in some easy way, like in the example I showed below, and I would like to get only a 2-dimensional subset of the larger data. The second part is, it would be really nice if the returned values were aliases/references to the original data, so that if I make a modification to the subset, it modifies the original, and vice versa (so basically, I want a "view" of the larger dataset). I know I could do this with Data::Alias or tied arrays, but again, maybe someone knows a module that already provides this. Here is the whole thing expressed in code:
use warnings; use strict; use Test::More tests=>2; sub getsubset { ... } my $data = [ ['a','b','c','d'], ['e','f','g','h'], ['i','j','k','l'], ['m','n','o','p'] ]; my $range = 'R2C2:R3C3'; # or any other useful syntax! my $subset = getsubset($data, $range); is_deeply $subset, [ ['f','g'], ['j','k'] ]; # Part 2: $subset->[0][1] = 'X'; $subset->[1][0] = 'Y'; is_deeply $data, [ ['a','b','c','d'], ['e','f','X','h'], ['i','Y','k','l'], ['m','n','o','p'] ];
|
---|