
FishMonger
Veteran
/ Moderator
Nov 1, 2017, 11:42 AM
Post #2 of 2
(2117 views)
|
Re: [gaetan3009] sed fetch line
[In reply to]
|
Can't Post
|
|
No reason to fork another process by going out to the shell to run a sed command. Perl has several ways to get a line on a specific line number. This is probably how I'd do it.
use strict; use warnings; use autodie; my $file = 'somefile.txt'; open my $fh, '<', $file; my $line; while ($line = <$fh>) { close $fh and last if $. == 4 } print $line;
(This post was edited by FishMonger on Nov 1, 2017, 11:43 AM)
|