Fellow monks, I have searched the internet high and low in every way that I can imagine but am unable to find a solution to my problem, so I come seeking the wisdom of those more well versed in the ways of hashes than myself: I run the following command and get the results as shown below:
/usr/local/bin/mpscli -S 10.11.10.2 -N username -P password show subsc +riber accountid="0000000 1111111" NAME: Last, First ACCOUNTID: 0000000 1111111 DESCRIPTION: ORGANIZATION: DEPARTMENT: OFFICE: EMAILADDRESSES: email@host.net BUSINESS1_PHONENUMBERS: BUSINESS2_PHONENUMBERS: HOME1_PHONENUMBERS: 555-1212 HOME2_PHONENUMBERS: CELLNUMBERS: PAGERNUMBERS: ADDRESS1: 150 Main Street ADDRESS2: CITYSTATE: City, State COUNTRYZIP: 99999 NOTE: Test modem @ home LOOKUPKEY: E136470EB3C911DCA53A00E081647FA8 CREATIONTIME: Wed Dec 26 07:47:36 2007 MODIFIEDTIME: Tue Nov 18 11:08:55 2008 CABLEMODEM: MACADDRESS: 000B06227472 MACADDRESS: 0015A2789F9B MTA: DEVICE: HOST:
I am putting all of this data into a hash by splitting the data and making everything before the ":" the Key and then putting in the corresponding data as the value. So far so good :) The problem lies when there are multiple MACADDRESS entries on an account. Typically there is only 1, but there could be as many as n entries there. I would like to put that data into the hash as well so I would get:
MACADDRESS=>6000B0227472 MACADDRESS2=>0015A2789F9B ... MACADDRESSn=><insert mac address here>
I am completely unsure how to do this. Any help is much appreciated. There is probably a MUCH better way to do this than I am doing it, but I understand what I am doing here, and that is important to me, I can evolve it later as my understanding gets better :) Here is the current code that makes the hash.
Notes: 1) @custinfo is where the data is returned from the command shown abo +ve 2) Not all data returned has a : in it, and we don't want that data so + we just work on the data that is seperated by a ':' 3) In the case of the MACADDRESS there are spaces in front of it, so w +e delete them. foreach (@custinfo) { if($_=~/:/){ my ($key, $data) = split (/:/,$_); $key=~s/\s+//g; $record{$key} = $data; } }
Like I said, there is a better way to do this I am sure, but at my current level of understanding, this works :) Not that it matters, but I also delete all hash keys that contain nothing...there is probably a better way to do that so that they are not included in the first place as well...LOL :)

Thanks in Advance


In reply to Question about a hash.... by raisputin

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.