I have a file with the following content:
sub is_top_level0 { # with comment
print '\nFollowed by comment \n'; # The comment
# line from begin
}
I'm, basically, using the following code where $sFilename
is set to the right file name:
use PPR;
open(DATAIN, $sFilename);
my @aFileData = map({ s/\r$//g; $_; } <DATAIN>);
close (DATAIN);
my $aRawFileData= \@aFileData;
printf("Read:\n@{$aRawFileData}===============\n");
my $aUncommentFileData = PPR::decomment($aRawFileData);
printf("Uncomment:\n@{$aUncommentFileData}===============\n");
The output is:
Read:
sub is_top_level0 { # with comment
print '\nFollowed by comment \n'; # The comment
# line from begin
}
===============
Uncomment:
sub is_top_level0 { # with comment
print '\nFollowed by comment \n'; # The comment
# line from begin
}
===============
as can be seen the part named "Uncomment" still contains the comments.
How to handle this?
(Note problem might sound a bit silly, but I'm not a perl programmer, just trying to modify some existing code)
Edit: small clarification as I wrote in the comment on the answer from @Dada (and that has been added in the answer as well):
Probably not clear enough in the question, but I would like to have the data available in an array
$aRawFileData
and$aUncommentFileData
(with the line terminators\n
) so I can iterate over the arrays (as it is done at the moment).