Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > Processing larg...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 1384 of 1478
Post > Topic >>

Processing large data files.

by bills@[EMAIL PROTECTED] (Bill Stephenson) Apr 6, 2007 at 03:27 PM

Perl crashes when using the included script for large data files. How 
can I prevent this from happening?

Kindest Regards,

--
Bill Stephenson


Sample data source is a Delimited text file with the following fields:

FMT:STORE:TIKEY:TITLE:QTY:DC:COMPANY:ZONE

DV:043712:20882903:DVD-ALL THE KING'S M('06/WS/2D:8.00000:ECDC:Hlyw:4
DV:043712:20883071:DVD-ALTERED (2006/WS):8.00000:ECDC:Hlyw:4
DV:043712:20883070:DVD-AMERICAN PIE 5-****(UR/WS:32.00000:ECDC:Hlyw:4
DV:043712:20883253:DVD-BROOKLYN LOBSTER (WS):2.00000:ECDC:Hlyw:4
DV:043704:20882903:DVD-ALL THE KING'S M('06/WS/2D:16.00000:WCDC:Hlyw:4
DV:043704:20883071:DVD-ALTERED (2006/WS):8.00000:WCDC:Hlyw:4
DV:043693:20882903:DVD-ALL THE KING'S M('06/WS/2D:24.00000:ECDC:Hlyw:4
DV:043693:20883071:DVD-ALTERED (2006/WS):8.00000:ECDC:Hlyw:4
DV:043693:20883070:DVD-AMERICAN PIE 5-****(UR/WS:24.00000:ECDC:Hlyw:4
DV:043693:20883092:DVD-ZOMBIE NATION (2006/WS):4.00000:ECDC:Hlyw:4
DV:043670:20882903:DVD-ALL THE KING'S M('06/WS/2D:8.00000:ECDC:Hlyw:4

<code>

#!/usr/bin/perl

use strict;
use warnings;

# set-up our variable....

my $source = "dataSource.txt";
my $destination = "testOUTPUT.txt";

my $fmt = "";
my $storeno = "";
my $co = "";
my $dc = "";
my $zone = "";
my $store = "";
my $tikey = "";
my $title = "";
my $qty = "";
my $text1 = "";
my $text2 = "";
my $output = "";

my @[EMAIL PROTECTED]
 = "";


# start the work...

open my $IN, $source or die "Can't read source file $source: $!\n";

# put all the stores into an array (@[EMAIL PROTECTED]
)...
my @[EMAIL PROTECTED]
 = <$IN>;

foreach my $line(@[EMAIL PROTECTED]
) {

	($fmt, $store, $tikey, $title, $qty, $dc, $co, $zone) = 
split(/:/,$line);
		
	push @[EMAIL PROTECTED]
 $store;
	
}


# remove duplicate stores from the list...
my %seen = ();
my @[EMAIL PROTECTED]
 = ();

foreach my $item (@[EMAIL PROTECTED]
) {

     unless ($seen{$item}) {
         # if we get here, we have not seen it before
         $seen{$item} = 1;
         push(@[EMAIL PROTECTED]
 $item);
     }
}

# for each store in our @[EMAIL PROTECTED]
 store list we look for
# lines in our file that have a matching store

foreach my $uniqStore (@[EMAIL PROTECTED]
) {

	foreach my $line(@[EMAIL PROTECTED]
) {
	
		($fmt, $store, $tikey, $title, $qty, $dc, $co, $zone) = 
split(/:/,$line);
	
# if they match we create our entry for the destination file....
		if ($store eq $uniqStore) {
		
			$text1= "Street Date $source \n". "Company $co \n". "Distribution 
Center $dc \n". "Zone $zone \n". "Store Number $store \n\n";
		
			$text2 .= "$tikey \t $title \t $qty\n";
			
			}
	
	 }
	
# then add it to the final $output.
	if ($text1 ne "") {
	$output .= 
"$text1$text2\n####################\n####################\n\n\f\n";
	$text2 = "";
	}
}

# and finally print all out

# print $output; #for debugging

open(my $DATA, "> $destination")
     or die (" Error 1.3 Couldn't file:: $destination for writing: \n");

print $DATA ($output);

close $DATA;
 




 2 Posts in Topic:
Processing large data files.
bills@[EMAIL PROTECTED]   2007-04-06 15:27:49 
Re: Processing large data files.
mumia.w.18.spam+nospam@[E  2007-04-06 23:45:58 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 18:58:15 CDT 2008.