Hey there good monks! I'm writing a small perl script to create 1000 files ("test_set_$i" here) with 400 gene IDs each (one per line). Then I must search for them in 4 other files (stored in @results). I'd rather use unix grep -f instead of doing a lot of Perl open/close and hash creating and accessing, which would be way too slower. The problem comes after iteration #204, in which the backticks call won't get the output in $tot_length and $? gets -1. Any idea why, please? I'm using Perl v5.14.2 in 64-bit Ubuntu 14.04. Here's that part of the code only:

for my $i(0..999){ + + my $tot_length = `grep -f test_set_$i $ARGV[2] | awk '{cnt += \$2}END{printf "%d", +cnt}'`; `grep -f test_set_$i $results[0] | awk '{print \$1}' | sed 's/>>//'| sort | uniq -c | awk '{print \$1*1000/$tot_length,\$2}' > out`; tie @{$files{'first'}[$i]},'Tie::File', "out"; `grep -f test_set_$i $results[1] | awk -F" : " '{print \$2}' | sort | uniq -c| awk '{print \$1*1000/$tot_length,\$2}' > out`; tie @{$files{'second'}[$i]},'Tie::File', "out"; `grep -f test_set_$i $results[2] | sed 's/ targets sites//' | sed 's/.*>//' | awk -F": " '{cnt[\$1]+=\$2} END{for (x in cnt){print cnt[x]*1000/$tot_length,x}}' > out`; tie @{$files{'third'}[$i]},'Tie::File',"out"; `grep -f test_set_$i $results[3] | awk '{print \$2}' | sort | uniq -c| awk '{print \$1*1000/$tot_length,\$2}' > out`; tie @{$files{'fourth'}[$i]},'Tie::File',"out"; `grep -f test_set_$i $results[4] | awk '{print \$2}' | sort | uniq -c| awk '{print \$1*1000/$tot_length,\$2}' > out`; tie @{$files{'fifth'}[$i]},'Tie::File',"out"; }

Thanks a lot!


In reply to Perl backticks not returning output by dannyjmh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.