andye has asked for the wisdom of the Perl Monks concerning the following question:
Quite a simple one, but it's puzzling me.
I'm trying to match each line of a string, including empty lines. I've found that foreach (/(.*)/gm) does the job - because if it sees two newlines in a row, then dot star matches (0 copies of any-character-but-newline) and it returns an empty string.
And that's fine. But then I thought to myself, hang on, I should be using split here, so I changed it to foreach (split /\n/) ...and it doesn't match empty lines.
I've looked in the Cameliad, but either it doesn't explain or (more likely) I'm not understanding correctly.
Could someone explain?
Cheers,
andy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Split and empty strings
by Rhandom (Curate) on Apr 10, 2001 at 19:27 UTC | |
by andye (Curate) on Apr 10, 2001 at 20:03 UTC | |
by davorg (Chancellor) on Apr 10, 2001 at 20:28 UTC | |
by Rhandom (Curate) on Apr 10, 2001 at 20:45 UTC | |
by chromatic (Archbishop) on Apr 11, 2001 at 00:44 UTC | |
by Rhandom (Curate) on Apr 10, 2001 at 20:39 UTC | |
by stephen (Priest) on Apr 10, 2001 at 21:15 UTC | |
by tilly (Archbishop) on Apr 10, 2001 at 22:25 UTC | |
|
Re: Split and empty strings
by davorg (Chancellor) on Apr 10, 2001 at 19:27 UTC | |
|
Re: Split and empty strings
by TheoPetersen (Priest) on Apr 10, 2001 at 19:22 UTC | |
by andye (Curate) on Apr 10, 2001 at 19:29 UTC |