NAME
Acme::Hyperindex - Look deep into structures using a list of indexes
SYNOPSIS
use strict;
use Acme::Hyperindex;
my @struct = (
{ j_psi => [qw( eta_prime phi kaon )] },
{ j_psi => [qw( selectron down tau_sneutrino )] },
{ j_psi => [qw( upsilon gluino photino )] }
);
print @struct[[ 2, 'j_psi', 1 ]], "\n"; ### Prints gluino
my $row = @struct[[ 1, 'j_psi' ]]; ### Row contains [qw( ... )]
DESCRIPTION
When you use dynamic datastructures, the perl index syntax may not be felxible enough. A little examle:
my @struct = (
{
pion => [
[qw(strange j_psi positron)],
[qw(down_squark electron gluino)],
],
w_plus_wino => [
[qw(neutralino tau kaon)],
[qw(charm_squark photino strange_squark)]
],
},
);
Now to get to the kaon particle, normally we use:
my $particle = $struct[0]->{w_plus_wino}->[2];
-- or better --
my $particle = $struct[0]{w_plus_wino}[2];
But what if you don't know how deep your datastructure is at compile time? 'Course this is doable:
my $particle = \@struct;
$particle = $particle->[$_] for qw(0 pion 2);
Two problems here: Perl will tell you 'Not an ARRAY reference' once we try to index in the hash on 'pion' with this array indexing syntax. It's damn ugly and looks complicated.
So Acme::Hyperindex lets you index on a .... amount of ...
my $particle = @struct[[ 0, 'pion', 2 ]];
-- or even --
my $particle = @struct[[ @indexes ]];
TODO
make hyperindex work for all perl's datatypes
AUTHOR
Berik Visschers <berikv@xs4all.nl>
COPYRIGHT
Copyright 2005 by Berik Visschers <berikv@xs4all.nl>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html