Hi Jim.

I think yu've got a bit lost in your nexted loops. I've tried to understand what
your code does and is meant to do and have written my interpretation
below. There are a few things that I can't fathom though.

Jim wrote:
> On Friday 04 April 2003 14:34, John W. Krahn wrote:
> > Jim wrote:
> > > I've never encountered this before but I have to be doing something
> > > wrong.
> >
> > Yes, you are.  This is the documented behaviour of the numeric variables
> > and is why we always tell beginners to use them only if the regular
> > expression matched.
>
> Ok.  I didn't put tests in my example code.  However, I do have tests in my
> actual code which is what led me to this whole fiasco.  In this code I am
> finding that the first test ($back) pasts...and rightly so.  It should.
> However, in the following regex ($line) it should fail sometimes...but it
> doesn't.  It doesn't because when $back returns $1 as a valid return from the
> regex then $1 remains a valid rval for the condition for $line.  I need to
> get around that!
>
> Here is my code:
>
>      76         for $back ( @data )
>      77         {
>      78             $go_on = 1;
>      79
>      80 # start infinite loop
>      81
>      82             while ( $go_on )
>      83             {
>      84
>      85 # if we see that there is a net_blk
>      86
>      87                 $back =~ /.*\(.*\) (.*?) .*/;
>      88
>      89                 if ( $1 )
>      90                 {
>      91
>      92 # add it to the array
>      93
>      94                     push(@ret,$1);
>      95
>      96 # walk it
>      97                     push(@done,$1);
>      98                     my @more = get_whois($1);
>      99
>     100 # repeat process
>     101                     for my $line ( @more )
>     102                     {
>     103                         $line =~ /.* \(.*\) (.*?) .*/;
>     104
>     105                         if ( $1 )
>     106                         {
>     107                             print "Pushing net_blk: $1\n";
>     108                             push(@ret,$1);
>     109                         }
>     110                         else
>     111                         {
>     112                             print "Go on to next iteration.\n";
>     113                             $go_on = 0;
>     114                         }
>     115
>     116                         print "Pushing $1 to [EMAIL PROTECTED] stack\n";
>     117                         last if ( grep($1,@done) );
>     118                     }
>     119                 }
>     120                 else
>     121                 {
>     122                     $go_on = 0;
>     123                 }
>     124             }
>     125         }

Take a look at this, which has something like your semantics:

    foreach my $back ( @data ) {

        next unless ( $back =~ /\)\s+(.+)\s+\(/ ) {

        push @ret, $1;
        push @done, $1;

        my @more = get_whois($1);

        foreach my $line ( @more ) {

            if ( $line =~ /\)\s+(.+)\s+\(/ ) {
                print "Pushing net_blk: $1\n";
                push @ret, $1;
            }
        }

        print "Pushing $1 to [EMAIL PROTECTED] stack\n";
        last if ( grep($1,@done) );
    }

The stack pushes are done in the equivalent place, but I think
they're not quite right; in particular the push to @ret is happening
teice. I could make neither head nor tail of your grep() call: all
I know is that it's wrong!

I hope this is a better starting point for you.

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to