String ref

[b][red]This message was edited by saridski at 2006-9-1 13:5:58[/red][/b][hr]
I am getting this:

Can't use string ("thrA") as a HASH ref while "strict refs"

On this line:

...
foreach (sort keys %GENES) {
print(F_OUT " >$_|");
print(F_OUT $_->{LOCATION}); #HERE
}
...

The KEY is actually a string type, in this case "thrA". How do I kill this error w/o removing use strict?

Thanks in advance!


Comments

  • : [b][red]This message was edited by saridski at 2006-9-1 13:5:58[/red][/b][hr]
    : I am getting this:
    :
    : Can't use string ("thrA") as a HASH ref while "strict refs"
    :
    : On this line:
    :
    : ...
    : foreach (sort keys %GENES) {
    : print(F_OUT " >$_|");
    : print(F_OUT $_->{LOCATION}); #HERE
    : }
    : ...
    :
    : The KEY is actually a string type, in this case "thrA". How do I kill this error w/o removing use strict?
    :
    : Thanks in advance!
    :

    Maybe I'm missing something from the code surrounding the snip you provided but here goes what I see.

    You're using $_ as a ref to hash %GENES when $_ is really the key. So you should be printing something like this:
    print F_OUT %GENES->{$_};

    X
  • [code][size=3]
    foreach (sort keys %GENES) {
    print(F_OUT " >$_|");
    print(F_OUT $GENES{$_}{LOCATION});
    }
    [/size][/code]
  • : [code][size=3]
    : foreach (sort keys %GENES) {
    : print(F_OUT " >$_|");
    : print(F_OUT $GENES{$_}{LOCATION});
    : }
    : [/size][/code]
    :

    Thanks to you both for your responses.
    Yes, I am using the default variable when Iterating the hash.
    Well done Kevin, works well. LOCATIONS is indeed an array and I think it's there I went wrong. I was trying to access it as if it was a hash when in fact, I was attempting to access an array.

    Here is how the structure is built:
    push(@{%GENES->;{$_}->{LOCATIONS}}, ({LOCATION => $_[0], DNA => undef}));

    Thanks very much.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories