rovf has asked for the wisdom of the Perl Monks concerning the following question:
The do FILENAME construct does not work if the last line in the file does not end in a newline. Bug or feature? For example, the program
produces as outputuse strict; use warnings; my $do_me="do_me.pl"; foreach my $ending ('',"\n") { print "Create file with",($ending?'':'out')," newline\n"; open(OUT,'>',$do_me) or die "$!"; print OUT "q(string)$ending"; close OUT; my $result=do $do_me; print "Can not read $do_me: $!\n" if $!; print "Can not evaluate $do_me: $@\n" if $@; print("$result\n") if defined $result; }
Create file without newline Can not read do_me.pl: Bad file descriptor string Create file with newline string
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why do we need a \n with do FILENAME?
by kennethk (Abbot) on Jul 06, 2010 at 15:34 UTC | |
by rovf (Priest) on Jul 06, 2010 at 15:57 UTC | |
by ikegami (Patriarch) on Jul 06, 2010 at 16:08 UTC | |
by rovf (Priest) on Jul 07, 2010 at 08:56 UTC | |
by ikegami (Patriarch) on Jul 07, 2010 at 15:50 UTC | |
by kennethk (Abbot) on Jul 06, 2010 at 16:23 UTC | |
by rovf (Priest) on Jul 07, 2010 at 09:23 UTC | |
by kennethk (Abbot) on Jul 07, 2010 at 14:32 UTC | |
by ikegami (Patriarch) on Jul 07, 2010 at 16:24 UTC | |
|