dwhite20899 has asked for the wisdom of the Perl Monks concerning the following question:
And here's split.pl#!/usr/bin/perl -w use strict; use vars qw( $filename ); ($filename = shift) or die "Usage: $0 filename\n"; open(FIN,"$filename") or die "$0 : cannot read file \"$filename\"\n"; # assume it is a text file while(<FIN>) { } print sprintf("%8s",$.) , " $filename\n"; close(FIN); exit;
I assumed these would be text files, not binary, and I kept Getopt out of it on purpose.#!/usr/bin/perl -w use strict; use vars qw( $linect $filename $prefix $i $postfix ); ($linect = shift) or die "Usage: $0 lines_out filename new_name \n"; $linect = int($linect); if ($linect < 1) { print STDERR "$0 : cannot split less than 1 lines\n"; exit; } ($filename = shift) or die "Usage: $0 lines_out filename new_name \n"; ($prefix = shift) or die "Usage: $0 lines_out filename new_name \n"; $i = 0; $postfix = sprintf("%02d",$i); open(FIN,"$filename") or die "$0 : cannot read file \"$filename\"\n"; open(FOUT,">$prefix.$postfix") or die "$0 : cannot write file \"$prefi +x.$postfix\"\n"; # assume it is a text file while(<FIN>) { print FOUT $_ ; if (($. % $linect) == 0) { close(FOUT); $i++; $postfix = sprintf("%02d",$i); open(FOUT,">$prefix.$postfix") or die "$0 : cannot write file +\"$prefix.$postfix\"\n"; } } close(FIN); exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mimicing wc and split
by BrowserUk (Patriarch) on Oct 05, 2006 at 01:48 UTC | |
by dwhite20899 (Friar) on Oct 05, 2006 at 14:29 UTC | |
|
Re: mimicing wc and split
by tilly (Archbishop) on Oct 05, 2006 at 01:39 UTC | |
|
Re: mimicing wc and split
by graff (Chancellor) on Oct 05, 2006 at 02:48 UTC | |
by shmem (Chancellor) on Oct 05, 2006 at 07:01 UTC | |
by dwhite20899 (Friar) on Oct 05, 2006 at 14:32 UTC |