The number of variables for each column will change from record to record.

This sample script tries to demonstrate what I am trying to do. Keep in mind, I am not an experienced Perl scripter and am trying to keep this simple.

#!C:\Perl\bin\perl.exe use Strict; use Warnings; @users = ( "UserID001|user1|password1|Fred|", "UserID002|user2|password2|George|", "UserID003|user3|password3|Mike|"); @admin = ( "AdminID001|admin1|password1|Joe|1|", "AdminID002|admin2|password2|Frank|1|", "AdminID003|admin3|password3|Carl|2|"); ($usernamesRef ,$passwordsRef ,$displaynamesRef) = arrayToMultiHash (\@users); # @users contains 3 columns besides Use +rID %usernames = %{$usernamesRef}; %passwords = %{$passwordsRef}; %displaynames = %{$displaynamesRef}; ($adminUsernamesRef ,$adminPasswordsRef ,$adminDisplaynamesRef ,$adminAccessLevelsRef) = arrayToMultiHash (\@admin); # @admin contains 4 columns besides Adm +inID %adminUsernames = %{$adminUsernamesRef}; %adminPasswords = %{$adminPasswordsRef}; %adminDisplaynames = %{$adminDisplaynamesRef}; %adminAccessLevels = %{$adminAccessLevelsRef}; print "User: $displaynames{'UserID002'} | $usernames{'UserID002'}\n"; print "Admin: $adminDisplaynames{'AdminID002'} | $adminUsernames{'Admi +nID002'}; sub arrayToMultiHash { my @array = @{$_[0]}; my @hashRefs; foreach $line (@array) { my @lineInfo = split (/\|/,$line); my $key = shift (@lineInfo); my $i = 0; foreach $value (@lineInfo) { my $hashName = "hash$i"; $hashName{$key} = $value; $i++; } } foreach (0..$i) { my $hashName = "hash$i"; push (@hashRefs,\%{$hashName}); } return (@hashRefs); }

Should print:

User: George | user2
Admin: Frank | admin2


In reply to Re: Creating dynamic hash names by Lamont85
in thread Creating dynamic hash names by Lamont85

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.