in reply to Re^2: System command not working
in thread System command not working
From your initial shell process, you launch a perl process which launches another shell process which launches another perl process. No, this is not the best way to do things. Except for the system() function, you initially seemed to be on the right track. Here's how I would have tackled this:
#!/usr/bin/env perl use strict; use warnings; my $infile = q{pm_read_part_file.in}; my $outfile = q{pm_read_part_file.out}; my $start = 3; my $end = 5; open my $in_fh, q{<}, $infile or die qq{Can't open $infile for reading +: $!}; open my $out_fh, q{>}, $outfile or die qq{Can't open $outfile for writ +ing: $!}; while (<$in_fh>) { next if $. < $start; last if $. > $end; print $out_fh $_; } close $in_fh; close $out_fh;
Here's a sample run with file contents:
en@ganymede: ~/tmp $ pm_read_part_file.pl ken@ganymede: ~/tmp $ cat pm_read_part_file.in Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 ken@ganymede: ~/tmp $ cat pm_read_part_file.out Line 3 Line 4 Line 5 ken@ganymede: ~/tmp $
-- Ken
|
|---|