Random style advice.

As perlstyle says, Always check the return codes of system calls.Good error messages should go to STDERR, include which program caused the problem, what the failed system call and arguments were, and (VERY IMPORTANT) should contain the standard system error message for what went wrong. So, for instance, where you write:

open INFILE, "$ARGV[0]";
you should write something like this:
open INFILE, "<", $ARGV[0] or die "Can't read '$ARGV[0]': $!";
And now if there is a problem opening that file, you'll get useful information.

Secondly you should familiarize yourself with strict.pm and apply what it says. That will catch a lot of typos in your code.

Thirdly you're using C-style for loops. Don't. Use Perlish for loops instead.

# I'd use a better variable than $line, but I don't know # what your purpose is, and your Tryptic names are quite # cryptic for me. for my $line (@aTryptic) { my $accSeq = SplitFields($line], 'split'); $line =~ s/\r?\n\z//g; $hTryptic{$accSeq} = $line; $line = $accSeq; }
This eliminates the possibility of off by one errors, is more efficient, and reduces possible typos.

Fourth, in question 2, either make all data chomped or all data unchomped. Having to call chomp on data randomly before comparing them is a red flag.

A more minor nit. I prefer using _ in variable names rather than camelCaseCapitalization.

Oh, and about question 2, rather than repeatedly scan an array, arrange to use a hash lookup.

my %in_array_b; @in_array_b{@array_b} = (); foreach my $one (@array_a) { print $in_array_b{$one} ? $hash_a{$one} : $hash_b{one}; }

In reply to Re: Can I make a sub for this? by tilly
in thread Can I make a sub for this? by sandrider

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.