I have this code which reads a file and then prints each string separated by a space in the next line in another file output1.txt. What I am wondering is if i remove $/ , it takes only the first line of uart1.txt. What is local doing here and in the end file handle is returned in $data? Is there any way I can do this task?
#!/usr/local/bin/perl
open STDOUT, ">", "output1.txt" or die "$0: open: $!";
use strict;
use warnings;
my $data= do {
open my $fh , '<','D:\perl_learning\uart1.txt' or die $!;
local $/;
<$fh>;
};
while($data =~ /(\S+)/g)
{
my $word=$1;
printf"%s\n",$word;
};