On 08/29/2006 05:02 PM, Dr.Ruud wrote:
"Mumia W." schreef:
Hien Le:

[...]
# Method 2
print( "\nMethod 2\n" );
my @bar2 = split( /([a-z]{5})/, $foo );    # Captures white-spaces
?!? [...]
The comments made by Dr. Ruud and John W. Krahn are correct.
Split is returning the empty strings between delimiter
segments in the original string. To zap these out, do this:

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 "()"?

Again: perldoc -f split


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'
        ];



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to