It seems someone taught you how to program outside of Perl before she taught you how to program inside of Perl. ;-)
Here's my riff on kcott's script…
#!/usr/bin/env perl
use strict;
use warnings;
use autodie qw( open close );
use English qw( -no_match_vars );
my $input_file = 'input.txt';
my $output_file = 'output.txt';
my $start = 17;
my $end = 30;
open my $input_fh, '<', $input_file;
open my $output_fh, '>', $output_file;
LINE:
while (my $line = <$input_fh>) {
next LINE if $INPUT_LINE_NUMBER < $start;
last LINE if $INPUT_LINE_NUMBER > $end;
print {$output_fh} $line;
}
close $input_fh;
close $output_fh;
exit 0;
And here's a greatly reduced version using <ARGV> and STDOUT instead of hardwiring file names inside the script…
#!/usr/bin/env perl
use warnings;
while (<>) {
next if $. < 17;
last if $. > 30;
print;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|