"Mumia W." schreef: > Dr.Ruud: >> Mumia W.: >>> my @bar2 = grep length, split (/([a-z]{5})/, $foo); >>> >>> Any substrings with a length of zero will be removed by "grep >>> length." >> >> Huh? Why not just remove the capturing "()"? > > Without the capturing parentheses, split will remove every > sequence of five alphabetic characters from the output. Only > 'pq' will remain: > > use Data::Dumper; > my $foo = 'abcdefghijklmnopq'; > my @foo = split /[a-z]{5}/, $foo; > print Dumper([EMAIL PROTECTED]); > > __END__ > > That program prints this: > > $VAR1 = [ > '', > '', > '', > 'pq' > ];
Aaargh, I was suddenly mixing up split /()/ and /()/g. I really shouldn't post anymore without testing. #!/usr/bin/perl use warnings ; use strict ; use Data::Dumper ; my $foo = 'abcdefghijklmnopq' ; my @foo = ($foo =~ /([a-z]{1,5})/g) ; print Dumper([EMAIL PROTECTED]); __END__ $VAR1 = [ 'abcde', 'fghij', 'klmno', 'pq' ]; -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>