in reply to Re: Use of uninitialized value in string eq
in thread Use of uninitialized value in string eq

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?

Replies are listed 'Best First'.
Re^3: Use of uninitialized value in string eq
by johngg (Canon) on Apr 21, 2010 at 22:42 UTC
    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

Re^3: Use of uninitialized value in string eq
by ikegami (Patriarch) on Apr 21, 2010 at 22:33 UTC

    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?
        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.

        If you show us some lines of data and explain how to identify individual components in a sequence (such that we know which is the 82nd, for example), we can explain how to write that code.

        I did not present a solution because it's not clear what you are trying to do. Giving us input samples and the output you expect to get from those inputs would be useful.