Those tutorials and resources are all great, and I heartily agree that you should spend some time with them; however, here's one possible answer to your immediate issue:
use strict; #These two lines are almost-always
use warnings; #a good idea
print "Enter your data.\n";
print "Type .. at the beginning of a line to quit.\n";
open my $output_file,'>','output_file.txt'
or die "We got trouble here!\n";
LOOP:
while (<STDIN>) {
my $data = $_;
chomp $data;
last LOOP if ($data =~ m/^\.\./);
print $output_file "$data\n";
}
close $output_file;
exit;
One of Perl's prime directives is that There Is More Than One Way To Do It. You could do this in fewer lines, sure, and there are many sorts of Perl idioms that would be shorter/more efficient/more elegant. But this can get you started. Welcome to Perl, and to PerlMonks!
UPDATE: added check for failed open(). There is more than one way to do this too: use autodie is what I usually do. Thanks, Happy-the-monk, for the reminder!
|