advice please wireless 802.11 on RH8 wrote:
> No, I meant an array to contain matches such as for:
>
> $_ = 'cat 12 Felix 17 Anytown NY';
>
> print "yes!"\n" if /^(cat|dog)\s+(\d+)\s+(\w+)\s+(\d+)/;
> # this mystery array would now contain qw(cat 12 Felix 17)
>
> ---------------------------------------
>
> It seems to me this would be common enough to store as a system array
> somewhere? By system array I mean one like @_ or @ARGV, etc.. ,
> something created for us by Perl...
Like I said before, just assign the results of the comparison to any array
you like:
#!/usr/bin/perl
use warnings;
use strict;
my @animals = ('cat 12 Felix', 'horse 20 Ed');
foreach (@animals) {
if (my @matches = /^(cat|dog)\s+(\d+)\s+(\w+)/) {
print join(',', @matches), "\n";
}
if (my ($species, $age, $name) = /^(cat|dog)\s+(\d+)\s+(\w+)/) {
print "Name=$name, age=$age, species=$species\n";
}
}
Why are you so insistent on a built-in array, anyway? I can understand being
lazy, but c'mon - is typing "my @matches = " such a hardship???
sherm--
--
Cocoa programming in Perl:
http://camelbones.sourceforge.net
Hire me! My resume:
http://www.dot-app.org