On Wednesday 09 January 2008 18:03:37 you wrote: > I have a file with thousands of fields, but a subsequent program can only > had 3000. I have to break this file up, for simplicity: > > 00001-03000 > 03001-06000 > > Hopefully, a basic outline of my code will suffice to get informative > advice. > > my $cnt = -1 ; > my $subset = 1 ; > > foreach ( 1..6000 ){ > > $cnt++ ; > > if ( $cnt = 0 ) { > $my file = "File_" . $subset ; > open CSV , ">" , "$file" ; > print CSV "$_[ $_ ]" ; > } > else{ > print CSV ",$_[ $_ ]" ; > } > > if ( $cnt == 3000 ){ > close CSV ; > $cnt = 0 ; > $subset++ ; > } > > } # cycled through all of the fields > > After I print the mod( $_ , 3000 ) = 0 field to the file, I close that > filehandle and reset $cnt to zero. I am not sure, but it seems that the > open function is not openning the subsequent filehandles. > > I would appreciate any corrections or suggestions. > > Kind regards, > > Kevin > > Kevin Viel, PhD > Post-doctoral fellow > Department of Genetics > Southwest Foundation for Biomedical Research > San Antonio, TX 78227
Kevin, There are a few issues with your example. First, the first conditional uses assignment rather than equality (= rather than ==), so it always evaluates to true. Also, probably just a typo, but "$my file" should be "my $file". Most importantly, the program is more complicated than it needs to be. A more concise and readable example might be something like: #!/usr/bin/perl open SUBSET1, ">", "subset1" or die "Cannot open 'subset1': $!\n"; open SUBSET2, ">", "subset2" or die "Cannot open 'subset2': $!\n"; while (<>) { print {$. <= 3000 ? SUBSET1 : SUBSET2} $_; } Stephen Kratzer Network Engineer II CTI Networks, Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/