in reply to Re: reg ex help
in thread reg ex help
Thanks for clarifying that ' ' is DWIM (magical) with respect to leading whitespace.
#!/usr/bin/perl use Data::Dumper; $_ = " foo bar baz "; my @a = split ' '; my @b = split /\s+/; print Dumper \@a; print Dumper \@b; __DATA__ $VAR1 = [ 'foo', 'bar', 'baz' ]; $VAR1 = [ '', 'foo', 'bar', 'baz' ];
What interests me from a 'why is it so?' point of view is that if \s+ splits at the begining of a string to find the NULL why not at the END as well. Your example documants the behaviour but why is leading whitespace treated differently from trailing whitespace? There is afterall a null string after the trailing whitespace as well.
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reg ex help
by Abigail-II (Bishop) on Apr 15, 2004 at 11:52 UTC | |
by pelagic (Priest) on Apr 15, 2004 at 12:06 UTC |