in reply to Use of uninitialized value in string eq

my @temp = $info{$humangi};
assigns one value to @temp, so you'll have a problem if $position is anything other than 0.

By the way, the following very suspicious:

my ($source, $position, $sink) = split(/(\d+)(\w)/, $Variant);

Specifically, /(\d+)(\w)/ doesn't look like it would match a separator. It should probably be

my ($source, $position, $sink) = $Variant =~ /(.*?)(\d+)(\w)/;

Replies are listed 'Best First'.
Re^2: Use of uninitialized value in string eq
by sophix (Sexton) on Apr 21, 2010 at 21:31 UTC
    Hi ikegami, thanks for the reply.

    I do not see why there would be a problem with the assignment of one value to @temp. My intention was to put the protein sequence (of human gi) into an array and then to point a position in this sequence. I thought I would bump into the problem you mentioned in case I would have used $temp, and actually that's why I used an array there. I would be glad if you can tell me what might be the problem.

    Suspicious, indeed. Yet it is working properly. I first used (\w)(\d+)(\w) and then modified it as to have the current one following the errors I got. I guess it first makes a split as P and 82L and then makes a second split by separating 82 and L. Your alternative looks more appropriate to use though.

    Any idea concerning the use of 'eq' operator?

      Any idea concerning the use of 'eq' operator?

      ikegami has already given you the answer to that. Your line

      my @temp = $info{$humangi};

      assigns a single scalar value to element zero only of the @temp array and no other element is initialised, but your line

      my ($source, $position, $sink) = split(/(\d+)(\w)/, $Variant);

      assigns the value of 82 to $position using your example of "P82L" in $Variant. Your comparison

      if ( $temp[$position] eq $source) {

      attempts to access element 82 of @temp which does not exist, hence the warning.

      I hope this clarifies things for you.

      Cheers,

      JohnGG

      I do not see why there would be a problem with the assignment of one value to @temp.

      What do you think $temp[82] returns when @temp only has one value? undef.

      I guess it first makes a split as P and 82L

      split is designed to split a separated list, but there's no separator between the fields in "P82L".

      Yet it is working properly.

      In the same sense that towing your car to work is a working alternative to driving to work.

        Thank you John and ikegami. As I was afraid, it seems that I do still have difficulties with the basics of Perl (or rather of programming).

        So the problem seems to have started when I first read the sequence line as $info{$gi}=$line;.

        And then, @temp = $info{$humangi} operates as such $temp[0] = $info{$humangi}. I hope I get this right.

        Thus, a possible solution is to store the sequence into an array in the beginning. To be frank, I do not know how to do this. Alternatively, there might be a way to convert a scalar value to an array list. (I would use split but as I see from your last comment on the use of split function, this is not a good way to do it.

        Can you help me on this one?