I don't know COBOL, but this doesn't make a lot of sense to me:

$Employee_Rec = [ {Emp_No=>1, Emp_Lname=>2, Emp_Fname=>3, Emp_SSN=>4, Emp_DOB=>5, Emp_aka=>6} ];

That's an anonymous array with a single element, an anonynmous hash where the values are sequential integers. What were you trying to accomplish by creating this structure? Are you by any chance trying to use the deprecated psuedo-hash system?

Later in the code it looks like you're treating $Employee_Rec as a simple hash-ref, which makes more sense. If that's what you want you don't need to do any pre-initialization and the "magic code" you're looking for is probably something like:

my @data = split(',',$_); $Employee_Rec->{Emp_No} = $data[0]; $Employee_Rec->{Emp_Lname} = $data[1]; ...

That will only work for very simple CSV files though - if you're dealing with something more complicated take a look at Text::CSV_XS.

-sam


In reply to Re: Loading an anonymous hash by samtregar
in thread Loading an anonymous hash by pglenski

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.