stu96art,

Note: These are suggestions, or just some things to think about!

In your assignment code below (abbreviated), you need some testing for input accuracy.

$flag_assignments{$key}{"starrez"} = $info[0]; . . . $flag_assignments{$key}{"NR-Spring"} = $info[10];

Since the question about your script wouldn't be needed if the input data was 100%, try doing some reasonable verification before building the hash.

If you are building the input data, why not build it as a hash record, i.e.

my $record = qq|startez\t$info[0]$sep . . . |; ## $sep is a field +separator defined by you

You can 'split' on the separator("$sep") to get the record into fields, and a simple 'foreach' loop to build the hash by 'split'ing on tab("\t"). Then you know the hash is correct. You can write this record to a file or send it to a database. Perl doesn't care how big it is, and you won't either. If fields are added, your original data will still be correct.

If you don't have control over the input, then what will happen if one field is added in the middle of the record? Checking on the exact number of fields will at least let you know that something is wrong, and you can fix it.

Once you verify the input, your script will do what you want.

Good Luck...Ed

"Well done is better than well said." - Benjamin Franklin


In reply to Re: Not meaning to add values to a hash by flexvault
in thread Not meaning to add values to a hash by stu96art

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.