"Michael S. Robeson II" <[EMAIL PROTECTED]> wrote ...

> use warnings;
> use strict;

Excellent. Make sure all your programs inlude these line.

Three of the lines below have problems.

> while (<DATA>) {
>    if (/>(\w+)/) {
>      $animal = $1;
>    } else {
>      while (/(-+)/g) {
>        my $gap_length = length $1;
>        my $position = pos ($1);

1. You really want
   my $position = pos $_;  # or just pos
   perldoc -f pos

>        $gap{$animal}{$gap_length}++;

2. First you tell Perl to create key called "human". You then store a
reference to another hash as its value with a key named "3". So far so good.
You then tell Perl to increment the value that already there via the "++".
Since there is no defined value, it essentially increments undef to 1. It
might not be obvious but this is a problem. Read on.

>        push (@{$gap{$animal}{$gap_length}}, $position);

3. You now tell Perl to create an array where the scalar value of "1"
already exists from above. You then receive a fatal error: 'Can't use string
("1") as an ARRAY ref while "strict refs" in use at dnagap6.pl line 16,
<DATA> line 2.'

Don't think in terms of lesser programming languages. Think Perlish. You can
safely delete the autoincrememt line from above and simply do:
   push @{$gap{$animal}{$gap_length}}, $position;

The lack of parens makes the prior statement slightly more legible. The
first time you execute this statement, the keys "human", and "3" do not
exist. However, Perl creates them when you execute the push statement.

I assume that you want the autoincrement to keep track of the number of
occurrences of human gaps of length 3. This information is contained by the
array length at @{$gap{$animal}{$gap_length}}. Does that look familiar? It
should because you just pushed an element onto it above!

Furthermore, you never use the variable %gap_pos. You also record $position
and then read from it exactly one time. You can delete the "my $position"
line altogether and do instead:
   push @{$gap{$animal}{$gap_length}}, pos;   # pos really means "pos($_)"
as stated earlier

Make sure you read
perldoc perlref

-ZO




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to