Yes, what you have is already pretty clean. So here's some thoughts and suggestions, anyways.

I suggest you take this code and shove it down into a subroutine. See Ovid's post Linear programming is bad for why — mainly that it allows you (and maintainers who follow you) to see the toplevel flow without sweating the details. You'll have a decision to make. You can either implement a general &split_record_into_arrays function or a more specific &split_into_city_county_state. The former is cleaner and more general. The latter gives more opportunity for validating your data. E.g., making sure that every state really is a legal state.

Perhaps this is just a class assignment and the point is to learn how to manipulate data structures. But if this is a real app, why to you want to apply 'uniq' to a list of cities? Why would you want to have just one city-entry for Springfield, Maine and Springfield, Ohio? And then why wouldn't you want to combine Akron and AKRON?. Right now, if you have a record with only two fields, you put an undef in the last list; is that OK? And you don't detect records with four fields.

throop


In reply to Re: cleaner code .... by throop
in thread cleaner code .... by tdevil76

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.