Thank you very much hexcoder and others for prompt response, let's go back to the root of the problem and see why I ended up to construct this wierd structure. I have a file like the following:
CLS_S3_Contig100_st CLS_S3_Contig100 53 10 0.3717 CLS_S3_Contig100_at CLS_S3_Contig100 55 11 0.4321 CLS_S3_Contig100_st CLS_S3_Contig100 57 10 0.3223 CLS_S3_Contig100_at CLS_S3_Contig100 59 11 0.4055 CLS_S3_Contig100_st CLS_S3_Contig100 61 11 0.4511 CLS_S3_Contig100_at CLS_S3_Contig100 63 11 0.474 . . . CLS_S3_Contig10031_st CLS_S3_Contig10031 53 12 0.5548 CLS_S3_Contig10031_st CLS_S3_Contig10031 57 10 0.4871 CLS_S3_Contig10031_st CLS_S3_Contig10031 61 12 0.547 CLSS3627.b1_F19.ab1 CLS_S3_Contig10031 62 11 0.5129 CLSS3627.b1_F19.ab1 CLS_S3_Contig10031 64 11 0.5789
Each field is tab separated. The second (let's call it origin) and third columns (let's call it PIP) are important to me. As you can see the third column is jumping from one or more units to the next. What I want to do is to create a file with the same columns with an extra 0 and 1 column. I will explain what are 0 and 1. for each origin (2nd column) I want PIP starts from 1 to its max in the file. Therefore at each origin change I will start from 1 to the max. for example for Contig100 max is 63, therefore, I will have a hash with multiple value that key is contig100 and values go from 1 to 63.This should be done at each origin change. Now that we have this hash, I need to compare it with my file that is already opened. If Contig100 and PIP=63 exist then in the new column put 1 if not put 0. Therefore for PIP 1 to 52 I will have all 0's then at 53, 54, 55 to 63 I will have 1's and so on. Here is the code that I wrote.
my %hash_F2_1 =(); my %hash_F2_2 =(); my %hash_F2_3 = ();my %hash_F2_4 += (); while(<INPUT2>){ (my $probeset_id, my $origin, my $probeseq, my $pip, my $gc, +my $affyscore) = split("\t", $_); push (@{$hash_F2_1{$origin}}, $pip); # This makes a hash of m +ultiple value for each probeset ID } #clculate the max and put into hash (origin and max of pip) for (sort keys %hash_F2_1){ #print RESULTS "$_", "\t", max(@{$hash_F2_1{$_}}), "\n"; $hash_F2_2{$_} = max(@{$hash_F2_1{$_}}); } # then go thorough $hash_F2_2 and that has the key (origin) # and max +as value and make a multivalue hash as follows: for my $k (sort keys %hash_F2_2){ my $v = $hash_F2_2{$k}; #print RESULTS "$k\t$v\n"; for (my $i=1; $i <= $v; $i++){ push (@{$hash_F2_3{$k}}, $i); # this hash (%hash_F2_3) is the hash of origins and PIPs from 1 to max } } LOOP1: foreach my $key(sort keys %hash_F2_3){ LOOP2: foreach my $position (@{$hash_F2_3{$key}}){ LOOP3: foreach my $key1(sort keys %hash_F2_1){ LOOP4: foreach my $position1(@{$hash_F2_1{$key1}}) +{ LOOP1: foreach my $key(sort keys %hash_F2_3){ LOOP2: foreach my $position (@{$hash_F2_3{$key}}){ LOOP3: foreach my $key1(sort keys %hash_F2_1){ LOOP4: foreach my $position1(@{$hash_F2_1{$key1}}) +{ if ($key =~ m/$key1/ && $position==$position1 ) { print "$key\t$position\t1\n"; } else { print "$key\t$position\t0\n"; } } } } }
This code does not work appropriately, although my rational seem to be ok.

In reply to Re^2: Complex Data Structure by sesemin
in thread Complex Data Structure by sesemin

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.