A friend of mine wants tools like "wc -l" and "split" from unix on his windows box, and fortunately he is allowed to run Perl. Here's what I came up with. My problem is coming up with appropriate test cases; I need a second (or more) pair of eyes . Here's linect.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;
And here's split.pl
#!/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;
I assumed these would be text files, not binary, and I kept Getopt out of it on purpose.

In reply to mimicing wc and split by dwhite20899

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.