
Kenosis
User
Apr 4, 2013, 8:24 PM
Post #2 of 3
(637 views)
|
Here's one way:
use strict; use warnings; my @sentences; print "Please enter 10 sentences.\n"; for ( 1 .. 10 ) { print "\nSentence $_ (press <Enter> when done):\n"; my $sentence = <>; push @sentences, $sentence; } open my $fh, '>', 'input.txt' or die $!; print $fh $_ for @sentences; close $fh; print "\nThank you.\n"; This first prompts the user for the 10 sentences, then enters a for loop that iterates 10 times, getting a sentence each pass and pushes those sentences onto an array. The array's elements are then written out to a file. Hope this helps!
|