Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: system() issue

by vinoth.ree (Parson)
on Dec 13, 2013 at 05:02 UTC ( #1066969=note: print w/ replies, xml ) Need Help??


in reply to system() issue

Hi,

My suggestion is, Check the exit status of the command , which is set in the special variable $?. To get the real exit status of the command you have to shift right by 8 the value of $? ($? >> 8).

If the value of $? is -1, then the command failed to execute, in that case you may check the value of $! for the reason of the failure.


All is well


Comment on Re: system() issue
Re^2: system() issue
by Anonymous Monk on Dec 13, 2013 at 14:46 UTC

    OK,I've checked the exit values of all of the components of the script and they all exit with a status of 0. However, when trying to make my script smaller, I realized that it works fine if I simply have the first subroutine print a txt file. So it seems to me that the issue has to due with this subroutine:

    sub rep_set{ open(FILE, "Superior_seqs2.txt") ||die; $/=">"; my%hash=(); my$hashref=\%hash; while(<FILE>){ if($_ =~ /^(.+?)\((\d+)\)(.+)\n(.+)/){ my$site=$1;my$count=$2;my$qiime=$3;my$seq=$4; $hashref -> {$seq}{$site}=$count; }else{ print "ERROR!\n" } } open (TABLE, ">>OTU_TABLE.txt")||die; open (REP,">>rep_set.txt")||die; my$seq_label=0; for my$seq_key(keys %hash){ $seq_label++; print REP ">$seq_label\n$seq_key\n"; print TABLE ">$seq_label\t"; for my$site_key(keys %{$hash{$seq_key}}){ my$counts="$hash{$seq_key}{$site_key}"; #print "$counts\n"; for(my$i=0;$i<=$counts;$i++){ print TABLE "$site_key\t"; } } print TABLE "\n"; } close FILE;close TABLE;close REP; }

    The file that is being opened has the following format:

    >ZZ2(12)orig_bc=GTAGCAACGTC new_bc=GTAGCAACGTC bc_diffs=0 TACGAAGGGACCTAGCGTAGTTCGGAATTACTGGGCGTAAAGCGCGCGTAGGCCGTTGAGTTAGTTAATT +GTGAAATCCCAAAGCTTAACTTTGGAACTGCAATTAAAACTGCTCGACTAGAGTTTGATAGAGGAAAGC +GGAATACATAGTGTAGAGGTGAAATTCGTAGATATTATGTAGAGCACCAGTTGCGAAGGCGGCTTTCTG +GATCAACACTGACGCTGAGGCGCGAAAGTATGGGTAGCAAAGAGG >ZZ2(6)orig_bc=GTAGCAACGTC new_bc=GTAGCAACGTC bc_diffs=0 TACGAAGGGACCTAGCGTAGTTCGGAATTACTGGGCGTAAAGCGCGCGTAGGCCGTTGAGTTAGTTAATT +GTGAAATCCCAAAGCTTAACTTTGGAACTGCAATTAAAACTGCTCGACTAGAGTTTGATAGAGGAAAGC +GGAATACATAGTGTAGAGGTGAAATTCGTAGATATTATGTAGAACACCAGTTGCGAAGGCGGCTTTCTG +GATCAACACTGACGCCGAGGCGCGAAAGTATGGGTAGCAAAGAGG >ZZ2(15)orig_bc=GTAGCAACGTC new_bc=GTAGCAACGTC bc_diffs=0 TACGTAGGGACCTAGCGTAGTTCGGAATTACTGGGCGTAAAGCGCGCGTAGGCCGTTGAGTTAGTTAATT +GTGAAATCCCAAAGCTTAACTTTGGAACTGCAATTAAAACTGCTCGACTAGAGTTTGATAGAGGAAAGC +GGAATACATAGTGTAGAGGTGAAATTCGTAGATATTATGTAGAACACCAGTTGCGAAGGCGGCTTTCTG +GATCAACACTGACGCTGAGGCGCGAAAGTATGGGTAGCAAAGAGG

    it has ~39,000 entries

      To avoid potential headaches, always localize assignments to global variables like $/.

      local $/ = '>';

      That way, the value of $/ will be automatically restored after the sub exits. Later parts of your program might not like having a weird line terminator dropped on them.

      Also good practice to localize $_ if you're using it for that type of while loop.

      local $_; while (<FILE>) {

        Thanks, that solved my problem. I had to localize the $/ value. :)

        Also, if you have any suggestions to make my code more readable, I would appreciate it. Not being from a computer background, I don't have much experience making it readable by others. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066969]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-08-27 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (252 votes), past polls