in reply to works on command line, but not from perl

Why don't you make it in perl instead of command line ?

There are more than one way to do it

my $file = 'text.txt'; open my $fh, '<' , $file or die $!; my @data = <$fh>; close $fh; print scalar @data;

If you still insisting on doing it through the command line then this might work

system( 'cat text.txt|wc -l| sed \'s/^[ \t]*//\'|sed \'s/[ \t]*$//\'' +);

Replies are listed 'Best First'.
Re^2: works on command line, but not from perl
by elwoodblues (Novice) on Feb 12, 2010 at 02:28 UTC
    Thank you. This is part of a much larger bash script that I'm porting. Yes doing it in entirely in perl was the long term goal, but in the first instance, I just wanted to get it running, even using system calls, as it saved me time (or so I thought).
      This is part of a much larger bash script that I'm porting.

      Then one of the first things you should be doing is understanding what the shell script was trying to do, instead of just wrapping "system()" calls around things.

      The idea is the get the same things done with code that is shorter, more efficient, easier to understand, and more resilient to a wider range of edge and error conditions. Using four independent processes in a system call just to get a line count on a file (or things to that effect) seems like the wrong way to go about it.