Ask a Question related to PERL Beginners, Design and Development.
-
Gautam Chaurasia #1
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
-
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... -
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... -
#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: ... -
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... -
how to make a global scope array
<20030725224852.1123.qmail@pb1.pair.com> Jack Lee: global $a; -
R. Joseph Newton #2
Re: How can be the return value from a subroutine saved in global array
gautam chaurasia wrote:
Here you just told the sub that it was done. It returns the single value it was> 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);
instructed to.
Joseph>
> }
> }
> }
R. Joseph Newton Guest
-
R. Joseph Newton #3
Re: How can be the return value from a subroutine saved in global array
gautam chaurasia wrote:
Identifiers--why are you wasting characters on the misleading '_name' portion ot> 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');
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]
I wish I knew what you are trying to do, so does the compiler/interpreter. We>
>
> 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
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
-
Robin Sheat #4
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:
To extend this a touch, just because of the number of people I've seen> 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]
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



Reply With Quote

