semi has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I post again my question with some changes.Part of my script is like this:

#!/usr/bin/perl -w use strict; use warnings; my $taxId = [0-9]; my $taxId1 = $ARGV[0]; my $taxId2 = $ARGV[1]; my $C = getDistance ($common_node); print $C; sub getParent { my ($taxId) = @_; my @parent_list = ""; while ($taxId = $taxId1){ my $parent = `getz "[taxonomy:$taxId1]" -f pid`; chomp $parent; $parent =~ s/PARENT ID :/ /; $taxId1 = $parent; push @parent_list, $parent; # } return @parent_list; } sub getDistance { my ($common_node) = @_; my $id; my $count; do{ $id = getParent ($taxId); $count++; }until ($id eq $common_node); return $count; }

There are some points I have to mention. First in command line I put two taxId1 and taxId2. But I also use taxId (that can be any digit and I am not sure is true or not). Second $common_node is just a number that I defined in main program(not in this post) and I want to find distance between this point and taxId1 or taxId2. In the first subroutine (get parent) I found some numbers that one of those is $common_node and just I want to count from the first number until that point ($common_node). Any response would be appreciated.

Replies are listed 'Best First'.
Re: do until question
by Corion (Patriarch) on Sep 08, 2011 at 14:45 UTC

    Your code does not even compile. Please post real, tested code.

    Also, please explain in English what this line is supposed to do. Also show and explain what steps you have taken to verify your assumptions:

    my $taxId = [0-9];

    This line of code is likely wrong:

    while ($taxId = $taxId1){

    Please explain what the while loop is supposed to do.

Re: do until question
by BrowserUk (Patriarch) on Sep 08, 2011 at 14:51 UTC

    Your code as posted doesn't make sense.

    • What do you think this: my $taxId = [0-9]; does?
    • Where does $common_node come from?
    • What do you hope to achieve by comparing an array reference with a string: while ($taxId = $taxId1)?
    • What do you think happens when you return an array of values: return @parent_list;

      and assign them to a single scalar: $id = getParent ($taxId);?

    That'll do for now.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      What do you hope to achieve by comparing an array reference with a string: while ($taxId = $taxId1)?

      I would not call that operation "comparing". For me and for perl, it looks like an assignment.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        True, but that wasn't his intent was it.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: do until question
by semi (Initiate) on Sep 09, 2011 at 08:07 UTC

    Hi,Thanks everyone who had command. might be my explanation had a problem.But any way I try to solve it for myself.

      Hi,Thanks everyone who had command. might be my explanation had a problem.

      Yes, which is why we asked you several questions in hopes you would explain

      But any way I try to solve it for myself.

      Good luck :)