in reply to Break sentence into two part
Something like below may do what you want. Although it's not exactly clear from your question why you want to do this, or what you have tried so far. You may get a better answer, if you can provide more details of what problem you are trying to solve and example code you have tried.
<code> Output: Perl 5 is a highly capable, feature-rich programming language with over 27 years of developmentuse strict; use warnings; my $sentence = 'Perl 5 is a highly capable, feature-rich programming l +anguage with over 27 years of development.'; my @words = split( ' ', $sentence); my $midpoint = sprintf("%d", scalar @words / 2); my ( @first_half, @second_half ); my $count = 0; for ( @words ) { push @first_half, $_ if $count <= $midpoint; push @second_half, $_ if $count > $midpoint; $count++; } print join( ' ', @first_half ) . "\n"; print join( ' ', @second_half ) . "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Break sentence into two parts
by Athanasius (Archbishop) on Jan 24, 2015 at 07:43 UTC | |
Re^2: Break sentence into two part
by pme (Monsignor) on Jan 24, 2015 at 09:08 UTC |
In Section
Seekers of Perl Wisdom