Dear PerlMonks,

I would appreciate any advice you have about a problem I have running a Perl script on the newer Mac operating systems.

I wrote a script to read each line of an input table for a pair of coordinates to extract segments from a long DNA sequence. (The whole script is below.) It worked on my old MacBook Pro with the Snow Leopard operating system. It still works on my student's non-Mac laptop. However, when I run it on my new MacBook Pro (Mavericks) or my Mac desktop (Mountain Lion), it only takes the first line of input, as if it is ignoring the while loop. It never gives me an error message.

I tried installing xcode, perlbrew, and Perl 5.18, but that didn't help. The perl -v command told me that I was running Perl 5.16. I deleted xcode and everything in the Perl folder in the Library (versions 5.8, 5.12) and any other Perl folder I could find, and it still runs the script with just the first line of input, and there is still a version 5.16 somewhere inside the computer. I don't know what to do, and Apple support has no idea either.

Muktak Aklujkar

The script:

#!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $inputFile; my $sequenceFile; my $outputFile; my $template; my %hashComps = ("T"=>"A", "G"=>"C", "C"=>"G", "A"=>"T", "N"=>"N"); my %hashStrand = ("f"=>"+", "r"=>"-", "+"=>"+", "-"=>"-"); Getopt::Long::Configure ('bundling'); GetOptions ('i|input_file=s' => \$inputFile, 's|sequence_file=s' => \$sequenceFile, 'o|output_file=s' => \$outputFile); if(!defined($inputFile)) { die ("Usage: FASTAgeneratorDNA.pl -i <input file> -s <sequence file> - +o <output file>\n"); } if(!defined($sequenceFile)) { die ("Usage: FASTAgeneratorDNA.pl -i <input file> -s <sequence file> - +o <output file>\n"); } if(!defined($outputFile)) { die ("Usage: FASTAgeneratorDNA.pl -i <input file> -s <sequence file> - +o <output file>\n"); } open (INFILE, "<$inputFile") or die( "Cannot open file : $!" ); open (SEQFILE, "<$sequenceFile") or die( "Cannot open file : $!" ); open (OUTFILE, ">$outputFile") or die ("Cannot open file for output: $ +!"); my $DNAsequence = ""; while (my $line = <SEQFILE>) { chomp($line); if ($line =~ />/) { #if line contains FASTA header after any amount of + whitespace next; } else { $DNAsequence .= $line; } #end of else structure } #end of while loop for each line while (my $coordinates = <INFILE>) { my @coordinates_array = split /\s+/, $coordinates; my $seqid = $coordinates_array[0]; my $strand = $hashStrand{$coordinates_array[1]}; my $start = $coordinates_array[2] - 1; my $stop = $coordinates_array[3] - $start; print (OUTFILE "\n>$seqid"); $template = substr($DNAsequence, $start, $stop); my $revcomp = ""; if ($strand eq "+") { print (OUTFILE "\n$template"); } elsif ($strand eq "-") { while ($template) { my $lastbase = uc(chop($template)); my $nextbase = $hashComps{$lastbase}; $revcomp .= $nextbase; } #end of while loop for revcomp print (OUTFILE "\n$revcomp"); } else { die( "Please specify the strand with a plus or minus symbol."); } #end of else structure } #end of while loop for each set of coordinates close (OUTFILE) or die( "Cannot close file : $!"); close (SEQFILE) or die( "Cannot close file : $!"); close (INFILE) or die( "Cannot close file : $!");

In reply to Script ignoring while loop on Mountain Lion and Mavericks by maklujkar

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.