#!/opt/bin/perl -w use strict; use IO::File; use File::Basename qw(basename); my $input = ""; #used as counters my $fn_count = $ARGV[0] - ($ARGV[0] - 1); my $fn_cyc_count= $ARGV[0]; my $org_fn; #used for File::Basename my $base; my $path; my $type; main(); exit(0); sub main{ while($fn_cyc_count >= 1){ open(IN, $ARGV[1])||die "Cannot open $ARGV[1]:$!\n"; die "No number of lines\n" unless($ARGV[0] =~ /^\d+$/); #Get $max_ln_count per file using $ARGV[0] $lines = 0; $lines ++ while(); close IN; my $max_ln_count = int($lines/$ARGV[0]); #Get Input from $ARGV[1] open(INFILE, '<' ,$ARGV[1]) ||die "Cannot open $ARGV[1] for data input!\n"; my $fh = IO::File->new($ARGV[1], 'r') ||die "unable to open $ARGV[1] for reading.\n"; my @all_lines = $fh->getlines(); my @rev_all_lines = reverse (@all_lines); #Output one of the new files in the current directory while($max_ln_count >= 1){ #Use File::Basename to get the file name. $org_fn = $ARGV[1]; my $base = basename $org_fn; my $file = $base . $fn_count; #Cut and Write Output my $line = pop(@rev_all_lines); open (OUTFILE, '>' ,$file)||die "Cannot open $file to write output!\n"; print OUTFILE "$line" . "\n"; #Subtract one from the $max_ln_count counter $max_ln_count = $max_ln_count - 1; #Close method when counter reaches 0 close (OUTFILE) if ($max_ln_count <= 0); } #Subtract one from the $fn_cyc_count counter $fn_cyc_count = $fn_cyc_count - 1; #Close method when counter reaches 0 close (INFILE) if ($fn_cyc_count <= 0); } } #### username $: perl myprog.pl 4 /path/path/path/flie.ext ##$ARGV[0] is the number of output files desired.