CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Assigning many smaller values to a parent one, and having many parent values.

 



AndrewF
Novice

Jul 9, 2013, 12:45 PM

Post #1 of 2 (171 views)
Assigning many smaller values to a parent one, and having many parent values. Can't Post

To begin I apologize for the title of this post, Im new to Perl and didn't really know what to call this one. This is what my file looks like
US
MSFT
-----------
UN
JNJ
-----------
US
ORCL
-----------
CA
LLBT
-----------
UN
TNBI
-----------
Basically I need a bit of code that takes all of the 4 charecter entries that share the same 2 charecter ones (US,UN,CA) and puts them in a list that that would look something like this
US_: "MSFT","ORCL"
UN_:"TNBI", "JNJ"
CA_:"LLBT"
Ive heard about printf and sprintf and maybe those would help, or perhaps a hash, although Ill have to alphabetize the lists later on. I really appreciate any help on this, so far Ive been very impressed with this community and how much Ive learned!


FishMonger
Veteran / Moderator

Jul 9, 2013, 1:02 PM

Post #2 of 2 (167 views)
Re: [AndrewF] Assigning many smaller values to a parent one, and having many parent values. [In reply to] Can't Post

You'll want to use a HoA (Hash of Arrays) to store the data.

If your data is consistent in its format, I'd read-in the file in record mode using '-----------' as the record separator. Then split the record on the \n char to extract the key/value pair to be used in the hash.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives