I have a scalar varible storing data seperated by commas and newline characters. An example of that data would be something like:
John,Doe,Pine St,12345
Jane,Doe,Aspen Way,45678
Andy,Smith,Park St,79845
I use the following command to convert that data into a 2d array.
my @temp = map { [split /,/] } (split/\n/,$data);
after converting the data into a 2d array I would extract only the last names into an array. I would do something like this.
my @lastNames;
for my $i ( 0..$#temp)
{
push @lastName, $temp[$i][1];
}
I wanted to know if there was a way to skip the step of converting the scalar into a 2d array and go straight to the single array of the data I need. Any help I can get would be great.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.