[Omaha.pm] Could use your help

Jay Hannah jay at jays.net
Fri Jan 19 05:13:08 PST 2007


On Jan 18, 2007, at 11:38 AM, kiran bina wrote:
> FILE: Has a lot of entries  in random order of entries of my  
> interest.  I am interested in selected few whose name I wish to get  
> from IN using the subroutine
> Problem: This  prints only  'C' even when I have entries in IN  
> which should allow printing A or B.
> I think I do not have my return statement at the right place.
>
> while <FILE>
> {
>    $string= 'Foo';
>    $status= find_member_status($string)
>       if ($string eq $status)
>         {
>            if (defined $object)
>              {
>   Print "A";
>              }
>              else
>              {
>  Print "B";
>              }
>          }
>         else
>         {
>                Print "C";
>         }
> }
>
>
> sub find_member_status
> {
>     my $name= shift;
>     my $rval= 'NA';
>     my $no_match_name;
>     while (my $line=<IN>)
>     {
>         if ($line=~ /\>/)
>         {
>             $line=~ m/\>(gi\|\d+\|gb\|\S+\|)/;
>             $no_match_name= $1;
>             print "Name= $name\n";
>             print "After: $no_match_name\n";
>             if ($name eq $no_match_name)
>              {
>                $rval= $no_match_name;
>                # return $rval;
>                 last;
>             }
>
>         }
>     }
>                 return $rval;
> }

Hmm... I think down here

     $line=~ m/\>(gi\|\d+\|gb\|\S+\|)/;
     $no_match_name= $1;
     print "Name= $name\n";
     print "After: $no_match_name\n";

your regex is demanding 'gi|' followed by digits, etc.

So $no_match_name will always be undef or start with 'gi|' followed  
by digits, etc. You should see that when you print "After:  
$no_match_name" ... ?

So, when we back up to the top:

    $string= 'Foo';
    $status= find_member_status($string)
       if ($string eq $status)

$status will always be undef or start with 'gi|' followed by digits.  
So it will never eq 'Foo'.

Perhaps you meant to test if $status *contains* 'Foo'?

    if ($status =~ /\Q$string\E/)

?

HTH,

j



More information about the Omaha-pm mailing list