Connecting Tech Pros Worldwide Forums | Help | Site Map

Bulk loading into file in PERL

Newbie
 
Join Date: Dec 2006
Posts: 1
#1: Dec 27 '06
Hi All,

How to load bulk of records from one file to another file.Is there any memory allocation techiques available.Need suggestion in that....

Eg:
just reading the data from the file and changing some value and storing into another file .. It's happening for record by record .. But i want to insert bulk of record at the same time.


any response appreciatable..

Reg..
--------
Rock...

Member
 
Join Date: Nov 2006
Posts: 83
#2: Dec 27 '06

re: Bulk loading into file in PERL


What do you want to achieve? If memory consumption is a concern, line by line appending is preferrable.
Member
 
Join Date: Nov 2006
Posts: 83
#3: Dec 27 '06

re: Bulk loading into file in PERL


You can always do:
Expand|Select|Wrap|Line Numbers
  1. open my $f1, '<', 'file1' or die "Couldn't open file1: $!";
  2. open my $f2, '>', 'file2' or die "Couldn't open file2: $!";
  3.  
  4. while ( read $f1, my $tmp, 131072 ) {
  5.     $tmp =~ s/OLDVALUE/NEWVALUE/g;
  6.     print $f2 $tmp;
  7. }
OTOH, that does not prevent "some value" from being split between two chunks...
Reply