Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to store the output from foreach loop into variable/array without printing?

by vinoth.ree (Prior)
on Mar 11, 2014 at 07:31 UTC ( #1077801=note: print w/ replies, xml ) Need Help??


in reply to How to store the output from foreach loop into variable/array without printing?

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


Comment on Re: How to store the output from foreach loop into variable/array without printing?
Download Code
Re^2: How to store the output from foreach loop into variable/array without printing?
by hellohello1 (Sexton) on Mar 11, 2014 at 08:22 UTC
    Thanks! I'll think through and work it out :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1077801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2015-07-07 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls