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



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to