So I am currently trying to write a perl script that reads to a file and writes to another. Currently, the problem that I have been having is removing new line characters from parsed rows.I feed in a file like this
BetteDavisFilms.txt
1.
Wicked Stepmother (1989) as Miranda
A couple comes home from vacation to find that their grandfather has …
2.
Directed By William Wyler (1988) as Herself
During the Golden Age of Hollywood, William Wyler was one of the …
3.
Whales of August, The (1987) as Libby Strong
Drama revolving around five unusual elderly characters, two of whom …
Ultimately I am trying to put it into a format like this
1,Wicked Stepmother ,1989, as Miranda,A couple comes home from vacation to …
2,Directed By William Wyler ,1988, as Herself,During the Golden Age of …
3,"Whales of August, The ",1987, as Libby Strong,Drama revolving around five…
it sucessfully removes recognizes to each number but then I want to remove the \n then replace the "." with a ",". Sadly the chomp function destroys or hides the data some how so when I print after chomping $row, nothing shows... What should I do to correct this?
#!bin/usr/perl
use strict;
use warnings;
my $file = "BetteDavisFilms";
my @stack = ();
open (my $in , '<', "$file.txt" ) or die "Could not open to read \n ";
open (my $out , '>', "out.txt" ) or die "Could not out to file \n";
my @array = <$in>;
sub readandparse() {
for(my $i = 0 ; $i < scalar(@array); $i++) {
my $row = $array[$i];
if($row =~ m/\d[.]/) {
parseFirstRow($row);
}
}
}
sub parseFirstRow() {
my $rowOne = shift;
print $rowOne; ####prints a number
chomp($rowOne);
print $rowOne; ###prints nothing
#$rowOne =~ s/./,/;
}
#call to run program
readandparse();