in reply to Re: system() issue
in thread system() issue

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

Replies are listed 'Best First'.
Re^3: system() issue
by Anonymous Monk on Dec 13, 2013 at 15:53 UTC

    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. :)