
Chris Charley
User
Oct 5, 2011, 6:21 PM
Post #2 of 3
(652 views)
|
|
Re: [fixles] Move first n lines from one file to anther
[In reply to]
|
Can't Post
|
|
I havent used either of the 2 modules you use but using Tie::File http://search.cpan.org/~mjd/Tie-File-0.96/lib/Tie/File.pm provides a way. There are other ways even without a module. I haven't tried the code that follows and it will change your master file so you may want to back it up before you run this code :-) Update: Changed the splice parameters to: print $new splice @array, 0, 100; was: print $new splice @array, 0, 100-1; I was off by 1. #!/usr/bin/perl use strict; use warnings; use Tie::File; my $master_file = '.\db\MASTER_DATA.csv'; my $new_file = 'START.csv'; #my $number_to_scan = 100; tie my @array, 'Tie::File', $master_file or die "Unable to tie $master_file.\n$!"; open my $new, ">", $new_file or die "Unable to open $new_file for writing.\n$!"; print $new splice @array, 0, 100; untie @array or die $!; close $new or die $!; I'm not sure that I can define a variable, (my @array), right there in the tie statement or if it needs to be defined before the tie statement.
(This post was edited by Chris Charley on Oct 6, 2011, 8:04 AM)
|