CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
"Out of memory"

 



navishkumarb
New User

Nov 11, 2010, 7:32 AM

Post #1 of 2 (441 views)
"Out of memory" Can't Post

Hi.
I just want to convert a 1D array into 2D array.
So when I am just running the script, I get "Out of memory" error. Can anyone help me in this issue.
Data file consists of only 90 lines.




Code
#!C:/Perl/bin/perl.exe -w 

open (Peptide1, "data.txt")|| die ("cannot open file");
@data = <Peptide1>;
$i=0;$j=0;

foreach $dat(@data)
{
while ($dat =~m/END IONS/)
{
$daten[$j][$i]=$dat;
$i++;

}
$j++;
}

close (Peptide1);



BillKSmith
Veteran

Nov 11, 2010, 10:40 AM

Post #2 of 2 (431 views)
Re: [navishkumarb] "Out of memory" [In reply to] Can't Post

Your while loop fills memory with copies of the first data item which contains 'END IONS'.

I am not sure exactly what you want, but in any case the following code will be close. Run it and observe how the input data gets organized. If it seems reasonable, try it with real data. (Uncomment the open and comment out the statement about *DATA.) Make changes as necessary. Continue to use Dumper to verify your results.


Code
#!C:/Perl/bin/perl.exe 
use strict;
use warnings;
use Data::Dumper;
*Peptide1 = *DATA;
#open( Peptide1, '<', "data.txt" ) || die("cannot open file");
my @data = <Peptide1>;
chomp @data;
my @daten;
close(Peptide1);

my $i = 0;
my $j = 0;
foreach my $dat (@data) {
$daten[$i][$j] = $dat;
if ( $dat =~ m/END IONS/ ) {
$i++;
$j = -1;
}
$j++;
}
print Dumper @daten
__END__
00
01
02
03
END IONS
10
11
12
13
END IONS
20
21
23
END IONS

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives