A
advice please wireless 802.11 on RH8
Is there some perl system array @? that has the values for ( $1 $2 $3
.... ) ? I don't see any in Camel.
BB
.... ) ? I don't see any in Camel.
BB
advice said:Is there some perl system array @? that has the values for ( $1 $2 $3
... ) ? I don't see any in Camel.
Sherm Pendley said:None that I know of, but you can easily assign the result of a match to an
array of your own:
my $string = 'foo:bar';
my @values = ($string =~ /(\w+)\w+)/);
mike said:I think the OP may mean $1 $2 $3 as in command line arguments, rather
than captured matches. (He refers to a "system array.") If so, @ARGV
is what you're looking for. @ARGV has any arguments as entered on the
command line.
^ ^ ^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)
advice said: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...
/^(cat|dog)\s+(\d+)\s+(\w+)/) {Sherm said: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) =
Sherm Pendley wrote:print "Name=$name, age=$age, species=$species\n";
}
}
advice said:It also seemed inconsistent that whenever Perl "can" capture arrays or
hashes, i.e. %ENV, @_, @ARGV, etc, it seems to like to do so. Here is a
case where it would be perfectly natural to capture $1 $2 $3 ... as an
array and it doesn't.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.