I'm not stevieb, but I think I can help you.
Update: mis-spelled stevieb's name previously - my goof!
To just get the address, use a "list slice". Let split do its thing and just select the parts that you want.
change my ( $age, $gender, $address ) = split /,/, $rest; to my ($address) = (split /,/, $rest)[-1]; or my ($address) = (split /,/, $rest)[2];
Perl can use a negative index! -1 in this case means "the last thing". index of 2 means 3rd thing from the left. Which one you use is dependent upon both preference and situation. In this case, the results should be identical.

As another point, if for example the address may contain comma's itself (maybe a street address in addition to the city name), you can limit the split with the 3rd parameter. (split /,/,$rest,3) allows max of 3 things in the split - that way the whole address would appear as the "last thing". BTW: I would use $city instead of $address if this is just a $city name (personal preference because $address implies something far more than just $city to me).

If this is a more complicated CSV file, with embedded commas which are quoted, using one of the CSV modules to parse this is the way to go - the CSV format is deceptively simple sounding, but the complications escalate dramatically when a comma (the field separator) can appear within one of the data fields.


In reply to Re^5: Splitting multiple patterns by Marshall
in thread Splitting multiple patterns by astronogun

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.