my \$snp_covered{\$mismatch}= \$snp_chip_covered; ...doesn't make sense.

You'll need to declare your hash as a lexical (my) variable outside the loop, so it won't get clobbered each time through. Then you can add keys to it in the normal way.

However, I don't quite understand what you're trying to do with %snp_covered. You're using the same key each time (\$mismatch, which is 3) and overwriting the previous value each time there's a match. If you just want to keep track of the total number of matches, you can use a plain scalar and just increment it each time:

```my \$count;
while(<INPUT2>){
chomp;
my @current_line  = split /\t/;
my \$mismatch =3;
next unless \$current_line == 1 &&
\$current_line >= \$mismatch;

\$count++;
}

Replies are listed 'Best First'.
Re^2: Hash making
by sesemin (Beadle) on Sep 21, 2008 at 04:52 UTC
Thanks Friedo,

I think was not clear enough. I just put \$mismatch = 3 to test if I can create a loop. So at each \$mismatch, I will have a series of line extracted let's say 1000000 for \$mismatch =1.

Then when mismatch changes to 2, another set of lines will be extracted. let's say 700000.

The goal is to have has with keys = different \$mismatches and values number of lines extracted.

Any further help is appreciated.

So at each \$mismatch

I don't understand "being at a variable".

I will have a series of line extracted let's say 1000000 for \$mismatch =1.

How do you determine how many lines to extract?

Then when mismatch changes to 2, another set of lines will be extracted. let's say 700000.

What causes \$mismatch to change?

I will have a series of line extracted

I don't understand "extracting a line". Do you mean "reading a line"? What do with the lines you've extracted?

Let's look at the following code. Up to counter1++ and forget the rest for now. with the conditions set (unless), I am taking those lines that are qualified. Counter1 gives me the number of counts for those lines (value for a hash). If I can iterate through \$current_line14 >= and change the value of 3 (which is fixed here) I will get different counts. Therefore by each change at value of current_line14 >= you will get a different count. So your hash keys become your loop values from 3..30 for example and values will be the number of lines extracted. If I want to change "3" manually I have to perform the while loop 20 - 30 times for each key in order to get the counts.
```while(<INPUT2>){
chomp;
my @current_line  = split /\t/;

# eliminate unqualified lines early

next unless \$current_line == 1 && \$current_line >= 3;

\$counter1++;

if (\$file1{ \$current_line}) {
my (\$from, \$to) = @{ \$file1{ \$current_line } };
for (\$from <= \$current_line && \$current_line <= \$to) {

print join("\t", \$current_line,\$current_line,\$current_line[14
+], "***",\$current_line), "\n";

\$lines++;
}
}
}