Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^3: System command not working

by kcott (Chancellor)
on Jul 10, 2012 at 07:51 UTC ( #980836=note: print w/replies, xml ) Need Help??

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{}; 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 $ ken@ganymede: ~/tmp $ cat 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980836]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2018-06-23 16:28 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.