On 10-05-20 12:52 PM, Akhthar Parvez K wrote:
Hi all,

Can Perl regex match a string in a list (like Perl grep)?
eg:-
#won't work
$_ = @data;
my @matches = /($regx)/g;
#works, but not as quite really wanted since it would show the line contains 
the string, not just the matched string:
my @matches = grep /($regx)/, @data;

So, can Perl grep show only the matched string like Unix egrep -o or Perl regex?


#!/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__


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

--
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