in reply to Splitting on uppercase letters
The secret is in the regular expression you use to split upon. I'm thinking zero-width positive look-ahead assertion but that's just me. Documentation is available at perlre and perlretut. If you're just starting out, perhaps you should check out perlrequick for an overview. But to answer your question:
#!/usr/bin/perl -wl $,=$"; print split/(?=[A-Z])/,"ThisString"; print split/(?=[A-Z])/,"SomeOtherString"; __DATA__ output: This String Some Other String
Hope this helps.
Updated: Just realized that I forgot to set $,. If not set as it is above, then the output would not have had spaces.
antirice
The first rule of Perl club is - use Perl
The ith rule of Perl club is - follow rule i - 1 for i > 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Splitting on uppercase letters
by davido (Cardinal) on Sep 10, 2003 at 20:16 UTC |