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 {
...
}
For example:
#!/usr/bin/perl
use strict;
use warnings;
{ local ($", $\) = (", ", "\n");
my @common;
my @powerball;
while (<DATA>) {
if ( /Powerball:/ ) {
if ( (my @numbers = /\b\d+\b/g) > 5 ) {
push @common, @numbers[0..4];
push @powerball, $numbers[5];
}
else {
print << "EOS";
*********
* ERROR * parsing input line $.
*********
EOS
}
}
else {
# do nothing
}
}
print "common : @common";
print "powerball : @powerball";
}
__DATA__
abc 01 def 02 ghi 03 ijk 04 lmn 05 Powerbalx: 06 xyz
abc 11 def 12 ghi 13 ijk 14 lmn 15 Powerball: 16 xyz
abc 21 def 22 ghi 23 ijk 24 lmn 25 Powerball: X6 xyz
abc 31 def 32 ghi 33 ijk 34 lmn 35 Powerball: 36 xyz
test
abc 41 def 42 ghi 43 ijk 44 lmn 45 Powerball: 46.3 xyz
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/