So I've written a code that checks to see if a key from Hash1 exists in Hash2.

When the select keys are found, I wish to pass the values associated with those keys (i.e. a nucelotide sequence) into a subroutine to space and label the rows/columns of the sequence. However, I'm not sure how to do this properly - possibly through referencing/dereferencing the hash?</p?

The main body of the code is below:

foreach my $samekeys (sort keys %hash1) { if (exists $hash2{$samekeys}){ ntSpacer(????); } } sub ntSpacer{ my $myseq= my $space; ### Prints number on top line to show groups of 10 nucleotides print " 1".$space." 2".$space." 3 +".$space." 4".$space." 5".$space. " 6".$space." 7".$space." 8".$sp +ace." 9".$space." 10"."\n"; ### Prints numbers per nucleotide, per groups of 10. print "Line".$space."1234567890".$space."1234567890".$space."1 +234567890".$space."1234567890".$space."1234567890".$space."1234567890 +". $space."1234567890".$space."1234567890".$space."1234567890" +.$space."1234567890"."\n"; ## For loop to set 100 nucleotides as maximum length o +f each line my $line_number=0; for (my $i=0; $i<length($myseq); $i=$i+100){ $line_number=$line_number+1; my $seq100=substr($myseq,$i,100); ## If line number is greater than or equal to 10, print +with custom spacing. if ($line_number>=10) { print " $line_number "; } else { print " $line_number "; } ## Divides every 100 nucleotides into groups of 10 with spac +es. for (my $j=0; $j<length($seq100); $j=$j+10) { my $seq10 = substr($seq100,$j,10); print "$seq10".$space; ## ^ Prints nucleotide sequence with spacers incorpora +ted into it. } } }

The end result I want is something like this, for multiple values (i.e. nucleotide sequences):

1 2 3 4 5 6 Line 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1 GGAAAAACAT TTCATCTTAA AACTTTCCTA AGACAAGGGA AAACAAAAAA CCATGCTCTA 2 TTTTTCTTAC AAAGAAAAAT TTAATATTCG ATGAGAGGTT GAACCAGGCT TAAAGCAGAC 3 ATGGTGCAGC CTGTAAGAAT GCCAGTTTGT AAGTACTGAC TTTGGAAAAG ATCATCGCCT 4 CTTAGGGTCC TGGTCTGGCA ATTTTGGCCT GATGTGATGC CACAAGACCC AACAGAGAGA 5 CCAGGATAAT GTTGACAGTG GTGTAGCCCT TTAGGAGAAA TGGCGCTCCC TGCGGCTGGT 6 CATTGGCACC GAAGGAACCA GGAGGATAAG AATATCCATA ATTTCAGAGC TGCCCTGGCA 7 CCCGTCGGAG GCTCTCACTG GCAAATGACA GCTCTGTGCA AGGAGCACTC CCAAGTATAA 8 ACAGTTTTAT TCTGAAGAAC ATTTTGCATT TTAATAAAAA AGGATTTATG TCAGGAAAGA 1 2 3 4 5 6 Line 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1 GGAAAAACAT TTCATCTTAA AACTTTCCTA AGACAAGGGA AAACAAAAAA CCATGCTCTA 2 TTTTTCTTAC AAAGAAAAAT TTAATATTCG ATGAGAGGTT GAACCAGGCT TAAAGCAGAC 3 ATGGTGCAGC CTGTAAGAAT GCCAGTTTGT AAGTACTGAC TTTGGAAAAG ATCATCGCCT 4 CTTAGGGTCC TGGTCTGGCA ATTTTGGCCT GATGTGATGC CACAAGACCC AACAGAGAGA 5 CCAGGATAAT GTTGACAGTG GTGTAGCCCT TTAGGAGAAA TGGCGCTCCC TGCGGCTGGT 6 CATTGGCACC GAAGGAACCA GGAGGATAAG AATATCCATA ATTTCAGAGC TGCCCTGGCA 7 CCCGTCGGAG GCTCTCACTG GCAAATGACA GCTCTGTGCA AGGAGCACTC CCAAGTATAA 8 ACAGTTTTAT TCTGAAGAAC ATTTTGCATT TTAATAAAAA AGGATTTATG TCAGGAAAGA etc.

Any suggestions are much appreciated.


In reply to Input Hash Values Into Subroutine by FIJI42

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.