How to split a paragraph into sentences using ".", "?", "!". and reverse those sentencen and finally join those splited sentences using thos relavent characters(".", "?", "!")?

I can't do the last joining part, can anyone do this problem reply me.........

Hi vassi,
Please show some example of what you have be able to do so far. With input, codes and desire results and possibly error messages. So that we can help.

for example,

input: my name is vassi. this is a book? he is a boy. his name is raj!

output: his name is raj! he is a boy. this is a book? my name is vassi.

this is the task, if anyone can, help me.

Hi,
Something like this:

#!/usr/bin/perl
use warnings;
use strict;

my $str = 'my name is vassi. this is a book? he is a boy. his name is raj!';

print 'Input: ', $str, $/;

my $seperator = qr/(\.|\?|\!)/;

my @word_arrays = split /$seperator/, $str;

print "Output:", rearragment( \@word_arrays );

sub rearragment {
    my ($words) = @_;

    my $new_formed_words;

    for ( reverse( 0 .. $#{$words} ) ) {
        if ( $_ % 2 != 0 ) {
            $new_formed_words .= $words->[ ( $_ - 1 ) ];
        }
        else {
            $new_formed_words .= $words->[ ( $_ + 1 ) ];
        }
    }
    return $new_formed_words;
}

OUTPUT
Input: my name is vassi. this is a book? he is a boy. his name is raj!
Output: his name is raj! he is a boy. this is a book?my name is vassi.

thankyou 2teez, but i have another problem, i need to do this task with file handling,

that means "write a perl script that reads a text from a file, reverses the sentences (puts the last sentence first, then the next to the last, etc, until the first sentence), and then outputs the resulting text into another file ",

can u help me?

Hi,
I guess the core of this threads has been done with. Really, it quite easy to read and write to file using function open() in perl.

However, you might have to check the usage open.Or you check previous solutions containing the function open on this section.

Am sure you will learn better, than for me, showing you all the solution.

Hope this helps.

Edited 4 Years Ago by 2teez

thank you 2teez, i found that problem, thanks for your help

Hi Vassi,

thank you 2teez, i found that problem, thanks for your help

That is the spirit. You are most welcome. Please, remember to mark this thread as SOLVED. thanks a lot.

This article has been dead for over six months. Start a new discussion instead.