JupiterHost.Net <[EMAIL PROTECTED]> wrote:
:
: [EMAIL PROTECTED] wrote:
: > Is there a module out there that I can use to parse
: > a text line and return the pieces that are enclosed
: > in paren's?
:
: You don't need a module for that just use regex's:
:
: my @text_inside_parens = $string =~ m/\((.*)\)/g;
Let's test it.
use strict;
use warnings;
use Data::Dumper 'Dumper';
foreach my $string (
'(foo) (bar)',
'(foo) (bar) (baz)',
'((foo) bar)) (baz)',
'(foo bar)', ) {
my @text_inside_parens = $string =~ m/\((.*)\)/g;
print Dumper [EMAIL PROTECTED];
}
__END__
I get:
$VAR1 = [
'foo) (bar'
];
$VAR1 = [
'foo) (bar) (baz'
];
$VAR1 = [
'(foo) bar)) (baz'
];
$VAR1 = [
'foo bar'
];
.* is greedy. I suspect @text_inside_parens will
never have more than one element in it.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>