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:
32 Bit Perl causing Segmentation Fault when input data is Huge

 



peacelover1976
New User

Mar 18, 2010, 4:42 PM

Post #1 of 1 (398 views)
32 Bit Perl causing Segmentation Fault when input data is Huge Can't Post

Hi Perl Gurus,

Iam quiet new to Perl and iam running into an issue which is beyond my reach now. I have a perl script which is causing segmentation fault (core) in AIX. The perl version is 32 bit and when i try to load a huge file of size 37 Mb in a hash, i get core dump. The line is

@{ $self->{lines}} = split('~', $line);



The $line has a huge single line data. I tried "tie" with DB_BTREE, DB_HASH, but nothing worked.

The code snippet is

sub new

{

my $class = shift();

my $self = {};

$self->{fname} = shift() or $self->{fname} = "STDIN";



# Open File Handle

if ($self->{fname} ne "STDIN")

{

# Check For Empty File

if (not -s $self->{fname})

{

#die "Empty or non-existent input file.\n";

return 0;

}

local *IN;

print "Before File Open\n";

open(IN, "< $self->{fname}") or return 0;

#die "Can't open $self->{fname} for input: $!\n";

print "After File Open\n";

$self->{file} = *IN;

$self->{fopen} = 1;

}

else

{

$self->{file} = *STDIN;

}



my $line = "";

while (not length($line))

{

print "inside while loop in X12.pm\n";

$line = readline($self->{file});

return 0 if (not defined($line));

$line =~ s/^\s+//; # Strip leading whitespace

print "line read from the file in X12.pm\n";

}



# Get Header Information and Initalize File Read Buffer

if ($line !~ /^ISA/)

{

$self->{fieldOut} = "*";

$self->{segOut} = "\n";

$self->{compSep} = "<";

$self->{fieldSep} = "\\*";

$self->{segSep} = "\\\n";

print "self in if cond in X12.pm\n";

}

elsif (length($line) < 106)

{

return 0;

#die "ISA segment invalid, aborting.\n";

}

else

{

$self->{fieldOut} = substr($line, 3, 1);

$self->{segOut} = substr($line, 105, 1);

$self->{compSep} = substr($line, 104, 1);

$self->{fieldSep} = "\\$self->{fieldOut}";

$self->{segSep} = "\\$self->{segOut}";

print "self in else cond in X12.pm\n";

}



print "self->{segSep} is $self->{segSep}\n";



@{ $self->{lines}} = split(/$self->{segSep}/, $line);



bless($self, $class);

return $self;

}

Please help me resolve this issue. I would like to have the return variable from split in a hash (@{ $self->{lines}} ), since this is being used by some more functions as input. Please help. One more thing i would like to add, moving to 64 bit perl is a final option which we are not looking into now.



Additional Information



-i am not aware of debugging perl core using GDB.

- i have written two small programs one using 32 bit perl and another the 64 bit perl . The 32 bit version core dumped where as the 64 bit did not.

-$ perl -v

This is perl, v5.8.0 built for aix

sample code using 32bit perl #!/usr/local/perl-5.6.1/bin/perlopen FILE, "20100317131946.cmb11cd8.60054.jcl.cmp.sent" or die $!;my $line;my @lines;my $self = {};my $i;while (<FILE>){ $line = $_; @lines= split("~",$line); #@{ $self->{lines} } = split("~",$line); print "Line copied into the data structure successfully\n"; #foreach $i(@lines) #{ # print $i; #}}

Sample code using 64bit perl #!/usr/opt/perl5/bin/perl5.8.2_64bitopen FILE, "20100317131946.cmb11cd8.60054.jcl.cmp.sent" or die $!;my $line;#my @lines;my $self = {};my $i;while (<FILE>){ $line = $_;# @lines= split("~",$line); @{ $self->{lines} } = split("~",$line); print "Lines copied into the data structure successfully\n"; }

Thanks, peacelover1976


(This post was edited by peacelover1976 on Mar 18, 2010, 4:50 PM)

 
 


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

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