我将总行数作为用户输入,然后我从文件中删除那些数字的l ine.
我看到了这个learn.perl.org/faq/perlfaq5.html#How-do-I-count-the-number-of-lines-in-a-file-然后我厌倦了以下简单的逻辑.
逻辑:
这是我的代码:
#!/usr/bin/perl -w
use strict;
open IN, "<", "Delete_line.txt"
or die " Can not open the file $!";
open OUT, ">", "Update_delete_line.txt"
or die "Can not write in the file $!";
my ($total_line, $line, $number, $printed_line);
print"Enter the number of line to be delete\n";
$number = <STDIN>;
while ($line = <IN>) {
$total_line = $.; # Total number of line in the file
}
$printed_line = $total_line - $number;
while ($line = <IN>) …Run Code Online (Sandbox Code Playgroud) perl ×1