On Thursday 20 May 2010, Shawn H Corey wrote:

> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> use Data::Dumper;
> 
> # Make Data::Dumper pretty
> $Data::Dumper::Sortkeys = 1;
> $Data::Dumper::Indent   = 1;
> 
> # Set maximum depth for Data::Dumper, zero means unlimited
> local $Data::Dumper::Maxdepth = 0;
> 
> my @data = qw( The quick brown fox jumped over the lazy dogs. );
> my $regx = qr{ [aeiou] }msx;
> my @matches = map { /($regx)/ } @data;
> print '@matches : ', Dumper \...@matches;
> 
> __END__
> 
> 

Thanks for the help, Shawn. 

Look at this code:

my @data = ( 'Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky.
123
Twinkle twinkle little star
How I wonder what you are');
my $rx1 = qr{ world.*diamond }imx;
my $rx2 = qr{ what.*world }mix;
my $rx3 = qr{ little\D*wonder }imx;
my $rx4 = qr{ high.*like }imx;
my @regex = ($rx1, $rx2, $rx3, $rx4);
my $regx = join ("|", @regex);
my @matches = map { tr/\n//d; /($regx)/g } @data;
print 'result: ', Dumper \...@matches;

and the output is:
result: $VAR1 = [
          'little starHow I wonder',
          'what you areUp above the world',
          'highLike',
          'little starHow I wonder'
        ];

The string that matches the regex 'world.*diamond' wasn't picked by the above 
expression. It looks like it was not picked because some part of the string was 
already picked by another regex. How can I get the expression pick that as well 
so the output would be like below:

result: $VAR1 = [
          'little starHow I wonder',
          'what you areUp above the world',
          'world so highLike a diamond',
          'highLike',
          'little starHow I wonder'
        ];

-- 
Regards,
Akhthar Parvez K
http://tips.sysadminguide.com/
UNIX is basically a simple operating system, but you have to be a genius to 
understand the simplicity - Dennis Ritchie

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to