Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: system() issue

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

in reply to system() issue


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

Replies are listed 'Best First'.
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:


    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066969]
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-03-25 14:01 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (311 votes). Check out past polls.