The error says:
Can't find string terminator '"' anywhere before EOF
and your code has:
print "$last_name;
# ^
Nothing to do with the regex.
Actually, the regex would be better not capturing the comma, and there is no need to quote the variable at all:
my $total_names = "Matthew,Thomas,Peter,Randy,George,Federick";
$total_names =~ /,([^,]+)$/;
print $1 if $1;
or
my $total_names = "Matthew,Thomas,Peter,Randy,George,Federick";
my ($last_name) = $total_names =~ /,([^,]+)$/;
print $last_name if $last_name;
Update: If your teacher does allow you to use split, you’ll get the last substring by subscripting with -1:
my $last_name = ( split /,/, $total_names ) [ -1 ] ;
(A [ 0 ] subscript gives you the first substring.)
Hope that helps,
Athanasius <°(((>< contra mundum
|