Strange output from using 'say'

Viewed 117

I need a second pair of eyes on this. I'm getting an extra newline whenever one of the conditionals (if or elsif) is true. I don't want that.

use strict;
use warnings;
use autodie;
use feature 'say';

my $filename = 'rr.txt';
open my $fh, '<', $filename;

while (<$fh>) {
  my ($last_name, $first_name, $country) = split /[,\|]/, $_;
  my $middle_name;
  $country =~ s/^\(//;
  $country =~ s/\)$//;
  say "Last Name: $last_name";
  say "First Name: $first_name";
  say "Country: $country";

  if ($first_name =~ /\w\s(\w+)/) {
     $middle_name = $1;
     say "Middle Name: $1";
  } elsif ($first_name =~ /\w\-(\w+)/) {
     $middle_name = $1;
     say "Middle Name: $1";
  }

}

The file looks like this:

Reid, Matt|(AUS)
Samper-Montana, Jordi|(ESP)
Krajonovic, Filip|(SRB)
Jones, Greg Luke|(AUS)
Burquier, Gregoire|(FRA)
Mandol, David|(ARG)
Daniel Llosa, Miguel Horpo|(DOM)

Whenever a middle name would get outputted it would be preceded by a newline. I don't know where that is coming from. The same thing happens by using print and appending a newline.

1 Answers
Related