in reply to Surprising capture of undef with zero repetitions
#!/usr/bin/perl # http://perlmonks.org/?node_id=1166285 use strict; use warnings; use Data::Dumper; sub f { my @tmp = "list $_[0]\n" =~ /\G(?:^list\s+|,)(\w+)(?=(?:,\w+)*$)/m +g; print(Dumper(\@tmp)); } f("foo"); f("foo,bar"); f("foo,bar "); # should fail on this f("foo, bar"); # should fail on this
produces
$VAR1 = [ 'foo' ]; $VAR1 = [ 'foo', 'bar' ]; $VAR1 = []; $VAR1 = [];
|
|---|