Can't find string terminator "str" anywhere before EOF

user490983 picture user490983 · Oct 29, 2010 · Viewed 9.8k times · Source

Why I get this error?

use strict;
use warnings;

my $str = <<str; 
88087   23/11/2010 
35192   25/07/2010 
B3J 5X9 17/08/2011 
C8U 5L6 16/08/2011 
F4Q 3B4 17/10/2010 
D3X 9P4 11/05/2010 
O7L 6Z8 28/02/2010 
W8L 9P2 05/09/2010 
str 

print $str;

my @arr = split/\n/,$str;
foreach (@arr) {
        my @tmp = split/\t/;
        print "$tmp[1]\n";
}

Answer

codaddict picture codaddict · Oct 29, 2010

You should not have a space here:

str 
   ^

The heredoc terminator should be on a line by itself and should not have anything (not even space) surrounding it.