in reply to Perl Split

One of my favourite debugging tools (apart from print) is Data::Dumper::Simple

If you are new to Perl (or even if you aren't), I'd really recommend getting into the habit of using it. It can very quickly and easily show you what's going on with your data - and it becomes especially useful once you start working with more complex data structures.

With regards to your current problem, as Corion points out, you're probably just forgetting about the whitespace after each period (full stop).

To demonstrate how Data::Dumper::Simple could have helped you to easily see this for yourself, consider the following:

#!/usr/bin/perl -w use strict; use Data::Dumper::Simple; my @lines; while (<DATA>) { chomp; @lines = split (/(?<=\.)/, $_); } print Dumper(@lines); __DATA__ First line. Second Line. Third line. Fourth line.
Which outputs:
@lines = ( 'First line.', ' Second Line.', ' Third line.', ' Fourth line.' );
So straight away it becomes apparent what's going on - ie. you are capturing the space after each period.

Hope this helps,
Darren :)

Replies are listed 'Best First'.
Re^2: Perl Split
by Gavin (Archbishop) on Mar 13, 2006 at 13:41 UTC
    Thanks again all for input;
    I have never used Data Dumper before.
    Please excuse my ignorance but when unzipped where do the various components go?

      Don't feel you need to excuse ignorance -- we were all there once (even if some of us forget from time to time)!

      It sounds like you're asking how to install Data::Dumper::Simple. For that, let me suggest you read A Guide to Installing Modules from the Tutorials section.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      If you are using ActiveState Perl on Win32, then all you probably need to do is open a command window and type "ppm install Data::Dumper::Simple"

      On a *nix system, then it would be "perl -MCPAN -e install Data::Dumper::Simple"

      But there is of course a lot more to understand about installing and using modules than that - so yes, as xdg suggests - check out the tutorials :)

        I'm using windows, tried to install from CMD but said try broader search first. Will try to install after reading tutorials. The only PM I have used so far has been "porter" and I just dropped it in the lib folder. This captured leading/trailing space is driving me crazy. Have posted again! Thanks again for all your help Gavin