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.


Right, The point was, regexes could help, I never said it wasn't greedy or the example was 100% what he needed, just a suggestion for another place to start looking :)
(I figured it was a *little* better than `perldoc perlre` ;p)

To illustrate further try:
perl -e 'my $str = "(hi)((bye)j(hi))(sweet)";my @m = $str =~ m/\(([^(^).]*)\)/g; for(@m) { print "-$_-\n"; }'


See? No module, lots of regex :) Again, maybe not exactly what they needed (IE It misses the middle 'j')but an illustration of an idea.

And so everyone who is playing along at home:
#!/usr/bin/perl

 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];
 }

HTH

Lee.M - JupiterHost.Net


Thanks for taking the time to do that example.


Lee.M - JupiterHost.Net

HTH,

Charles K. Clarkson



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




Reply via email to