in reply to Understanding regular expressions: why do I have to use map to clear up undefs in regex output?

BTW, the use of the statement  map { /.+/g } to filter out undefined values works only if the warning about uninitialized values in pattern matches is turned off, and has the additional shortcoming of filtering out empty strings.

Much better, IMO, to grep for only defined values (single-quotes used in example instead of double-quotes to avoid lots of escaping on XP command line):

>perl -wMstrict -MData::Dumper -le "my $str = q{1,2,3,4,'fine', '', 'day','today',}; my @f = grep defined, $str =~ m{ (\d+) | ' ([^']*) ' }xmsg ; print Dumper \@f; " $VAR1 = [ '1', '2', '3', '4', 'fine', '', 'day', 'today' ];
  • Comment on Re: Understanding regular expressions: why do I have to use map to clear up undefs in regex output?
  • Select or Download Code