in reply to Running a Perl Code within a Perl Code Using "Shell Module"

find -name '*.fasta' -maxdepth 1 -print0 \ | xargs -r -0 -P5 -n1 sh -c 'perl mycode.pl "$1" > ~/MyPerl/result_ans +/"$1".out' ''

Whenever you find yourself thinking “I want to start a bunch of processes like this one with different parameters,” xargs probably has your back. When it involves files, find -print0 | xargs -0 is the standard tool.

Or else you put parallelism into your main script itself – the feasibility of that varies. (In your case it would have to be adapted to create output logfiles per some sort of filename template.)

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^2: Running a Perl Code within a Perl Code Using "Shell Module"
by monkfan (Curate) on Nov 10, 2005 at 04:01 UTC
    Given this directory structure
    ~/MyPerl | |__ ans # this stores all the .fasta files (input) |__ result_ans # to store the result |__ mycode.pl
    Does this script does what it should:
    find ans/ -name '*.fasta' -maxdepth 1 -print0 \ | xargs -r -0 -P5 -n1 sh -c 'perl mycode.pl "$1" > ~/MyPerl/result_ans +/"$1".out' ''
    Cause it gives this message:
    : /home/myname/MyPerl/result_ans/ans/hm14_ans.fasta.out: No such file +or directory

    Regards,
    Edward

      No, that can’t work. As you can see in the error message, the path component is included in the logfile’s path. Just execute this from within ~/MyPerl/ans and omit the path argument to find, that’s the easiest solution.

      Makeshifts last the longest.