in reply to Query on Perl system command

Single quotes do not interpolate, you need double quotes, with alternate delimiters,
$filename =~ s/\.doc$//; qq(echo "$filename.txt\n$filename.xls\n" | phylip ); qq~echo "$filename.txt\n$filename.xls\n" | phylip ~;
See perlintro, perlop#Quote and Quote-like Operators

Replies are listed 'Best First'.
Re^2: Query on Perl system command
by Anonymous Monk on Mar 04, 2011 at 13:24 UTC
    When I modified

    system 'echo "$filename.txt\n$filename.xls\n" | phylip';

    with

    qq(echo "$filename.txt\n$filename.xls\n" | phylip );

    OR with

    qq~echo "$filename.txt\n$filename.xls\n" | phylip ~;

    I get the following error message

    "Useless use of string in void context at alignment.pl line 75."

    Any idea, why this is happening ? (I am newbie to perl)

    I appreciate your help

      I'm a newbie to your code.

      Which is / what's in "Line 75?"

        Oops... I copied entire error message !!

        qq(echo "$filename.txt\n$filename.xls\n" | phylip );
        This piece of code is in line 75

        If you allow me to complicate my script, The complete system command looks like this...

        system 'echo "4\n6\n3\n5\n\n1\n$filename.fsmi\n5\n$filename.phb\n111\n +1000\n4\n$filename.ph\n$filename.dst\n\n2\n" | phylip';

        phylip has many options, and user have to choose the option by pressing 1 or 2 or 3 or 4 ... etc. The point of giving output file name comes after choosing many such options. When I run "phylip" program separately (by "seperately", I mean, running "phylip" outside perl script) I type 1,2 or 3...etc and press ENTER key to choose that option. When I am calling "phylip" inside perl script, I use "\n" as a substitute for ENTER key

Re^2: Query on Perl system command
by Anonymous Monk on Mar 04, 2011 at 18:41 UTC
    You wrote

    qq(echo "$filename.txt\n$filename.xls\n" | phylip ); qq~echo "$filename.txt\n$filename.xls\n" | phylip ~;

    Your script would have been

    system qq(echo "$filename.txt\n$filename.xls\n" | phylip ); system qq~echo "$filename.txt\n$filename.xls\n" | phylip ~;

    I made a mistake by running your script blindly, so it didn't work that time. Yes you are right, single quotes do not interpolate, I needed double quotes !

    Thank you :-)