in reply to Surprising capture of undef with zero repetitions
Update 2: now another solution occurred to me, that appears to work:
(updated code to add: f("foo,bar,bar2,bar3"); - no regex change, just another data example)
One way is to use match global:#!/usr/bin/perl use warnings; use strict; use Data::Dumper; sub f { my $in = shift; my (@tmp) = "list $in" =~ /(?:^list\s+)?(\w+)/g; print(Dumper(\@tmp)); } f("foo"); f("foo,bar"); f("foo,bar,bar2,bar3"); __END__ $VAR1 = [ 'foo' ]; $VAR1 = [ 'foo', 'bar' ]; $VAR1 = [ 'foo', 'bar', 'bar2', 'bar3' ];
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; sub f { my $in = shift; my (@tmp) = $in =~ /(\w+)/g; print(Dumper(\@tmp)); } f("foo"); f("foo,bar"); __END__ $VAR1 = [ 'foo' ]; $VAR1 = [ 'foo', 'bar' ];
|
|---|