clothespeg has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get it to print in a txt file, but can't figure out why something like the following is not working:open(File, "file.txt"); while($text = <File>){ @words = split(' ', $text); for $word(@words){ print "$word\n"}};
I still consider myself new to perl so there must be something I don't get. Thanks in advance.open(S, 'file.txt'); while($text = <S>){ @words = split(' ', $text); for $word(@words){ my $filename = 'report.txt'; open(my $fh, '>', $filename) or die "Could not open file '$filename' $ +!"; print $fh "$word\n"; close $fh; print "done\n"; }};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Script works fine in cmd but doesn't print to txt
by Fletch (Bishop) on Jul 12, 2019 at 18:30 UTC | |
|
Re: Script works fine in cmd but doesn't print to txt
by haukex (Archbishop) on Jul 12, 2019 at 20:15 UTC |