Ok... That is my script
#!/usr/bin/perl -w use Fcntl; use Getopt::Std; use constant DIR => "/d/testing"; use constant MAX => 11; my $prog = $0; $prog =~ s|.*/||; my %opts; getopts('o:', \%opts); my $cmd = $opts{o} || 1; my @date = localtime(time); my $dd = sprintf ("%02d", $date[3]); my $mm = sprintf ("%02d", $date[4] + 1); my $yy = sprintf ("20%02d", $date[5] % 100); my $yymmdd = "$yy$mm$dd"; my @a; my $bnum; my $template = "A12 A4 A20 A20 A2 A2 A2 A2 A12 A4 A24 A24"; unshift (@ARGV, "-") unless @ARGV; for my $mfile (@ARGV) { $file = $mfile; open (IN, "< $file") or die ("Can't open $file: $!\n"); while (<IN>) { @normalDb = (); @errorDb = (); s/\s//g; $dd = $_; my @a = unpack($template, $dd); $sdate = $a[8]; $state = $a[4]; $err = $a[7]; $bnum = substr($a[3], skip_zero($a[3])); substr($dd, 37, 0) = '00' if ( $state eq '02' ); substr($dd, 62, 3) = '01' if ( $sdate !~ /^0/ && $err !~ /^0/ + ); substr($dd, 62, 3) = '01' if (length($dd) == 131); #The 2 last character of lines must be number if ($dd !~ /\d\d$/ || $dd =~ /<u$/ ) { $dd =~ s/..$/00/g; } #insert X for the rest if ( length($dd) < 130 ) { $dd = insert0($dd); } else { $dd = substr($dd, 0, 130); } if ( length($dd) == 130 ) { push (@normalDb, $dd); } else { push (@errorDb, $dd); } if ( @normalDb > 0 ) { my $path = "$file\.ok"; open (NORMAL, "+>> $path") or die $!; for (@normalDb) { print (NORMAL "$_\n") }; close (NORMAL); } if (@errorDb > 0 ) { my $path = "$file\.error"; open(ERROR, "+>> $path") or die $!; for (@errorDb) { print (ERROR "$_\n") }; close (ERROR); } } close (IN); } sub skip_zero { my ($a) = @_; my $j = 0; foreach my $i (split //, $a) { $j++; return $j if ($i > 0); } } sub insert0 { my ($tmp) = @_; my @data; push(@data, $tmp); for (my $i = length($tmp); $i < 130; $i++) { push(@data, "X"); } return sprintf ("%s", join('', @data)); } die;
As your info, the the file size is about 507156496 bytes....

In reply to Re: Script not working on large file size by bh_perl
in thread Script not working on large file size by bh_perl

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.