Hi i'm a new initiate seeking absolution about concatenating to keys within a hash. I have read that this is not allowed therefore i would ask the revered monks what approach i should take. I have been trying to understand hash referencing but this seems division one whilst i'm still playing Sunday league.

The hash %bact contains sequences as values and unique identifiers as keys. I am trying to add subsets to the unique identifiers in the keys and counts to the subsets

e.g. keys :- UniqueID_set1_0001, UniqueID_set1_0002, UniqueID_set1_0003, UniqueID_set2_0001.............

Perhaps someone could suggest a simpler way to do it or point me in the right direction about "hard referencing" . The documentation goes off on some very confusing tangents about this for a newbie.

I get no substitutions taking place either with "Use of uninitialized value in substitution (s///) error messages". I have tried searching the web .. this seems to be a common error message caused by many things and after spending hours trying to understand what's wrong i became a convert and decided to turn to the monastery for enlightenment. For any help gratefully received i would be truly thankful. Amen

#! /usr/bin/perl -w use strict; $set1count=000; $set2count=000; $set3count=000; $set4count=000; $set5count=000; foreach my $id (keys %bact) { if (($bact{$id} =~ m/^CAGGTGGCAT/)) { s/^CAGGTGGCAT//; $id .='_set1_'; $set1count++; $id .=$set1count; } elsif (($bact{$id} =~ m/^CATTGAAGCT/)) { s/^CATTGAAGCT//; $id .='_set2_'; $set2count++; $id .=$set2count; } elsif (($bact{$id} =~ m/^CTAAGTTCAG/)) { s/^CTAAGTTCAG//; $id .='_set3_'; $set3count++; $id .=$set3count; } elsif (($bact{$id} =~ m/^CTAAGAACGT/)) +{ s/^CTAAGAACGT//; $id .='_set4_'; $set4count++; $id .=$set4count; } else { s/^CTGGAGGACT//; $id .='_set5_'; $set5count++; $id .=$set5count; } } print "------------------------------------------------------ +---------\n"; print "-------- ABUNDANCE OF SEQUENCES WTHIN EACH SUBGROUP - +---------\n"; print "number of sequences in set 1 CAGGTGGCAT sub group = $se +t1count \n"; print "number of sequences in set 2 CATTGAAGCT sub group = $se +t2count \n"; print "number of sequences in set 3 CTAAGTTCAG sub group = $se +t3count \n"; print "number of sequences in set 4 CTAAGAACGT sub group = $se +t4count \n"; print "number of sequences in set 5 CTGGAGGACT sub group = $se +t5count \n"; ...

In reply to Concatenate to keys in a hash whilst doing substitution on values by Boz

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.