G'day colicab,

I'm not aware of a module that does this. Here's a fairly simple subroutine that may do what you want.

#!/usr/bin/env perl use 5.010; use strict; use warnings; use List::Util qw{first}; use constant { HOUSE => 0, FAMILY => 1, EXTERN => 2, EXTRAS => 3 }; use constant INDEX => qw{HOUSE FAMILY EXTERN EXTRAS}; my @table; my %cross; while (<DATA>) { push @table, [ split ]; } say crosslink(HOUSE, FAMILY, 9); say crosslink(HOUSE, FAMILY, 9); say crosslink(FAMILY, HOUSE, 10); say crosslink(EXTRAS, EXTERN, '8text'); say crosslink(EXTRAS, FAMILY, '8text'); say crosslink(HOUSE, EXTRAS, 12); say crosslink(HOUSE, EXTRAS, 13); sub crosslink { my ($in, $out, $val) = @_; my $key = $in . '-' . $val; if (exists $cross{$key}) { return $cross{$key}[$out]; } say 'Search once only:'; # for testing only - remove in producti +on my $found = first { $_->[$in] eq $val } @table; return 'Not found! ' . (INDEX)[$in] . ": $val" if ! defined $found +; $cross{$key} = $found; return $cross{$key}[$out]; } __DATA__ 1 2 3 4text 5 6 7 8text 9 10 11 12text 13 14 15 16text

Output:

$ pm_cross_table.pl Search once only: 10 10 Search once only: 9 Search once only: 7 6 Search once only: Not found! HOUSE: 12 Search once only: 16text

-- Ken


In reply to Re: Looking for an existing package to crosslink different IDs with each other by kcott
in thread Looking for an existing package to crosslink different IDs with each other by colicab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.