in reply to Printing specific line numbers

you can use Tie::File and treat the file as an array, and take an array slice:
use Tie::File; use Fcntl 'O_RDONLY'; my @array; my $filename = '/etc/passwd'; tie @array, 'Tie::File', $filename, mode=>O_RDONLY or die; open NUMS, "line_num_file" or die; my @line_nums = map { s/\s+$//s; $_ } <NUMS>; close NUMS; my @lines = @array[ @line_numes ];

Replies are listed 'Best First'.
Re^2: Printing specific line numbers
by sgifford (Prior) on Jun 01, 2006 at 22:00 UTC
    And as requested, here's a command-line version of that:
    perl -MTie::File -ne 'BEGIN{tie(@f,"Tie::File",shift,mode=>0,autochomp +=>0) or die "tie failed $!"} print@f[$_..$_+2]'

    Give the filename to read first, and any other filenames given will contain line numbers; if only one filename is given, numbers come from STDIN. For example:

    $ echo 0 |perl -MTie::File -ne 'BEGIN{tie(@f,"Tie::File",shift,mode=>0 +,autochomp=>0) or die "tie failed $!"} print@f[$_..$_+2]' /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin $