peacelover1976 has asked for the wisdom of the Perl Monks concerning the following question:
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.
Thanks, peacelover1976
|
|---|