From what I can make out the problem is that you have split all of the paragraphs into sentences. You then place each sentence into a separate cell.

my $Data = "Sentence One. Sentence Two. Sentence Three. Sentence Four. + Sentence Five."; @array=split(/\.$/,$Data); print "\n"; print "$_.\n" foreach @array;

this prints

Sentence One. Sentence Two. Sentence Three. Sentence Four. Sentence F +ive.

Firstly, consider removing the trailing '$' to print the following as this causes the line to be split at only the last '.'

Sentence One. Sentence Two. Sentence Three. Sentence Four. Sentence Five.

After this point you may need to execute some methods to concenate pairs of array elements into another array. Which you can then split into the cells as required. Try:

#! /usr/bin/perl -T use strict; use warnings; my $Data = " Sentence One. Sentence Two. Sentence Three. Sentence Four +. Sentence Five"; #my @array=split(/\./,$Data); my @array = split /\./, $Data; print "\n"; print "$_.\n" foreach @array; #my $count = scalar int(@array/2); my $count = int @array/2; my @joinarray; for (1..$count){ my $tmp = shift @array; $tmp .= ".".shift @array; push @joinarray, $tmp ; } #if (@array){my $tmp2 = shift @array; push @joinarray, $tmp2}; push @joinarray, shift @array if @array; print "\n"; print "$_.\n" foreach @joinarray; exit 0;

which prints

Sentence One. Sentence Two. Sentence Three. Sentence Four. Sentence Five.

I cannot see that you are opening a spreadsheet within this snippet though it contains instructions to set out code as if on an open spreadsheet. So I have determined the error to be within the data manipulation and have set out the solution as above.

There may be a couple of issues that you will need to reconsider as a result of a modification of flow such as this entails.

For the full stop problem you may need to enhance the pattern to fit the structure of the end of a sentence such as '.' being followed by a ' ' (space). And...

Extend the array counting variable routine to suppose variable length paragraphs.

If you need further help, please show what output you are getting, and the part of the programme you think is causing the error, and supply a brief explanation of what it is not doing that you want it to do.

Coyote

Closing statements updated as an afterthought.


In reply to Re: Extract lines from document to excel by Don Coyote
in thread Extract lines from document to excel by rajkrishna89

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.