Dr.Ruud wrote:
John W . Krahn schreef:
Dr.Ruud:
Jonathan Lang:

  while (<DATA>) {
    ($a[0], $a[1], $a[2], $a[3], $a[4], $b) = /(\d+), (\d+), (\d+),
(\d+), (\d+), Powerball: (\d+)/;
    push @common, @a; push @powerball, $b;
  }
A slightly different way to do that, is:

   while (<DATA>) {
     if (my @numbers =
           /(\d+), (\d+), (\d+), (\d+), (\d+), Powerball: (\d+)/) {
Another way to do that:

       /Powerball:/ and my @numbers = /\d+/g;


       push @common, @numbers[0..4];
       push @powerball, $numbers[5];
     }
     else {
       ...
     }
   }

I wouldn't use such a conditional "my".

So maybe you meant it more like:

    if ( /Powerball:/ ) {
        if ( (my @numbers = /\d+/g) >= 5 ) {
            push @common, @numbers[0..4];
            push @powerball, $numbers[5];
        }
        else {
            ....
        }
    }
    else {
        ...
    }

There is no conditional 'my': it is a delaration. I believe John was suggesting a replacement just for your conditional expression:

  if (/Powerball:/ and my @numbers = /\d+/g) {
    push @common, @numbers[0..4];
    push @powerball, $numbers[5];
  }
  else {
    :
  }

which isn't an equivalent to yours - it simply makes sure that the record contains 'Powerball:' and at least one digit - but I'm sure it is adequate. My own solution didn't even do this much checking, since I read the OP as saying that all irrelevant data records had been removed.

Rob

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


Reply via email to