How can be the return value from a subroutine saved in global array

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default How can be the return value from a subroutine saved in global array

    i tired like this, so it should get list of genes from subroutine gene and
    should print all the entries of array. but it gets only a single value. could
    someone please tell me where and what am i doing wrong...

    my $twig= new XML::Twig();
    $twig->parsefile( "local.xml");

    my $gene_list= $twig1->root;
    my @genes= $gene_list->children;

    chomp (my $qname = <STDIN>);

    sub gene{
    foreach my $gene ( @genes) {

    my $l_name = $gene->first_child( 'Localization');
    my $y_name = $gene->first_child( 'Yorf');
    my $g_name = $gene->first_child( 'Genename');

    my $local_name = $l_name->text;
    my $yorf_name = $y_name->text;
    my $gene_name = $g_name->text;

    if ($local_name eq $qname) {
    return($yorf_name);
    }
    }
    }

    @sname =[];
    @sname = gene();
    print @sname;

    Thanks in advance
    Gautam

    --
    +++ Mailpower für Multimedia-Begeisterte: [url]http://www.gmx.net/topmail[/url] +++
    250 MB Mailbox, 1 GB Online-Festplatte, 100 FreeSMS. Jetzt kostenlos testen!

    Gautam Chaurasia Guest

  2. Similar Questions and Discussions

    1. Global Array
      Hello, I want to organize XML information into an array that can be accessed by any function in the timeline. I also want to give the array an...
    2. Global array usage?
      This is probably one of the dumbest and simplest questions but I just can't find an answer. I have the following line in my PHP file: $version...
    3. #25410 [Opn->Csd]: strange crash & freeze bug when reassigning global var to method's return
      ID: 25410 Updated by: sniper@php.net Reported By: xuefer at 21cn dot com -Status: Open +Status: ...
    4. how to return all rows selected in subroutine?
      Howdy: I am trying to return an array of all records in the subroutine below. I want to hold all of that info in one location so that I can...
    5. how to make a global scope array
      <20030725224852.1123.qmail@pb1.pair.com> Jack Lee: global $a;
  3. #2

    Default Re: How can be the return value from a subroutine saved in global array

    gautam chaurasia wrote:
    > i tired like this, so it should get list of genes from subroutine gene and
    > should print all the entries of array. but it gets only a single value. could
    > someone please tell me where and what am i doing wrong...
    >
    > if ($local_name eq $qname) {
    > return($yorf_name);
    Here you just told the sub that it was done. It returns the single value it was
    instructed to.
    >
    > }
    > }
    > }
    Joseph

    R. Joseph Newton Guest

  4. #3

    Default Re: How can be the return value from a subroutine saved in global array

    gautam chaurasia wrote:
    > i tired like this, so it should get list of genes from subroutine gene and
    > should print all the entries of array. but it gets only a single value. could
    > someone please tell me where and what am i doing wrong...
    >
    > my $twig= new XML::Twig();
    > $twig->parsefile( "local.xml");
    >
    > my $gene_list= $twig1->root;
    > my @genes= $gene_list->children;
    >
    > chomp (my $qname = <STDIN>);
    >
    > sub gene{
    > foreach my $gene ( @genes) {
    >
    > my $l_name = $gene->first_child( 'Localization');
    > my $y_name = $gene->first_child( 'Yorf');
    > my $g_name = $gene->first_child( 'Genename');
    Identifiers--why are you wasting characters on the misleading '_name' portion ot
    the variable name, and shorting the information value. If the relevant
    information is 'left', then left should be $left intact. I say misleading,
    because if it was just a name, a string scalar, you wouldn't have to dereference
    the text from it below.

    Choose accurate and meaningful variable names, and don't try to save keystrokes.
    It's pointless. You will waste much more time and energy trying to keep track of
    what things really mean than you would have with the extra typing [hint--most
    editors have excellent copy-and-paste facilities for moving identifiers around]
    >
    >
    > my $local_name = $l_name->text;
    > my $yorf_name = $y_name->text;
    > my $gene_name = $g_name->text;
    >
    > if ($local_name eq $qname) {
    > return($yorf_name);
    > }
    > }
    > }
    >
    > @sname =[];
    > @sname = gene();
    > print @sname;
    >
    > Thanks in advance
    > Gautam
    I wish I knew what you are trying to do, so does the compiler/interpreter. We
    could probably help you. In my earlier response, I pointed to the specific line
    that was causing the problem you cited. Unfortunately, the overall purpose seems
    to have gotten lost amongst the code here.

    Better to write a simple, plain-language description of what data you are working
    with, and what information you seek to extract from it. Often, you can take such
    a description, and translate it very readily into working code. Code-first is
    unlikely to get you there.

    Joseph


    R. Joseph Newton Guest

  5. #4

    Default Re: How can be the return value from a subroutine saved in global array

    On Sun, Feb 01, 2004 at 10:50:44AM -0800, R. Joseph Newton wrote:
    > what things really mean than you would have with the extra typing [hint--most
    > editors have excellent copy-and-paste facilities for moving identifiers around]
    To extend this a touch, just because of the number of people I've seen
    not know this, play with meta(alt)-/ in emacs. It completes with things
    that start the same from elsewhere in the files you have open. Keep
    pressing for more options. Even more useful when working in Java, with
    its verbosity :)

    --
    Robin <robin@kallisti.net.nz> JabberID: <eythian@jabber.org>

    Hostes alienigeni me abduxerunt. Qui annus est?

    PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFAHY8TzTjgendttmMRAubCAKCVh+SZo1JN4+eGKB/IXKVP2HPvQgCdHQJT
    14z9DjJiB44efl40Jz7EVbw=
    =n8US
    -----END PGP SIGNATURE-----

    Robin Sheat Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139