Hi,

As per my understanding from your post, that you need data from __DATA__ area 3..4 and 5..6 in separate array of each row. I have saved data as another array ref, you can do deref and you can take data from each array.

There could be more efficient way, other than this.

use strict; use warnings; use Data::Dumper; my @arr = <DATA>; chomp @arr; my (@Arry1,@Arry2); foreach(@arr) { my @arr1 = split(/\s+/,$_); push (@Arry1,[@arr1[3..4]]); push (@Arry2,[@arr1[5..6]]); } print Dumper \@Arry1; print Dumper \@Arry2; __DATA__ AX8 0.23 42.4 1 1 1 1 AX4 0.65 53.6 0.2 7.8 9.1 2.3 AX12 0.34 23.9 3.2 7.2 1.2 9.3

All is well

In reply to Re: How to store the output from foreach loop into variable/array without printing? by vinoth.ree
in thread How to store the output from foreach loop into variable/array without printing? by hellohello1

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.