If you need to store the data in a new array (I'll assume an array of arrays), you could do this (reusing the data kindly provided by
Lennotoecom):
my @table = ('a b c d e', 'f g h i j', 'k l m n o', 'p q r s t', 'u
+v w x y');
my @table2 = map { [(split / /, $_)[1, 4]] } @table;
The @table2 array now looks like this:
0 ARRAY(0x803cc6d8)
0 ARRAY(0x8042f630)
0 'b'
1 'e'
1 ARRAY(0x8042f828)
0 'g'
1 'j'
2 ARRAY(0x8042f840)
0 'l'
1 'o'
3 ARRAY(0x8042f540)
0 'q'
1 't'
4 ARRAY(0x8042f870)
0 'v'
1 'y'
If you want an array of lines, changing the second line to:
my @table2 = map { join " ", (split / /, $_)[1, 4] } @table;
And the resulting array is now:
0 'b e'
1 'g j'
2 'l o'
3 'q t'
4 'v y'
Edit: I did not look at it very carefully at the time, but I see now that the second solution I suggested just above is almost the same as the one suggested by
Lennotoecom. Sorry for repeating almost the same thing, although this was not intentional.
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.