in reply to Why do we need a \n with do FILENAME?
#!/usr/bin/perl use strict; use warnings; my $do_me="do_me.pl"; print "(1)Can not read $do_me: $!\n" if $!; foreach my $ending ("\n", '') { print "Create file with",($ending?'':'out')," newline\n"; open(OUT,'>',$do_me) or die "$!"; print "(2)Can not read $do_me: $!\n" if $!; print OUT "q(string)$ending"; close OUT; my $result=do $do_me; print "(3)Can not read $do_me: $!\n" if $!; print "Can not evaluate $do_me: $@\n" if $@; print("$result\n") if defined $result; } print "(4)Can not read $do_me: $!\n" if $!;
outputs:
(1)Can not read do_me.pl: Bad file descriptor Create file with newline (2)Can not read do_me.pl: Bad file descriptor string Create file without newline (3)Can not read do_me.pl: Bad file descriptor string (4)Can not read do_me.pl: Bad file descriptor
As to why you get that pattern, my guess is internal try-catch structures within the open and do blocks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why do we need a \n with do FILENAME?
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 | |
by rovf (Priest) on Jul 08, 2010 at 07:58 UTC | |
|