Mailing List Archive

Strange lines order for: exec or print "foo"; die "bar"
When we use exec in form of: exec LIST or print "foo"; die "bar";
it gives wrong (I guess) lines order in output subject to presence of
"\n" in print statement:

perl -E 'use warnings; exec "echo 1" or print "First line";
die "Second line";'
1

perl -E 'use warnings; exec "echos 1" or print "First line";
die "Second line";'
Can't exec "echos": No such file or directory at -e line 1.
Second line at -e line 1.
First line

perl -E 'use warnings; exec "echos 1" or print "First line\n";
die "Second line";'
Can't exec "echos": No such file or directory at -e line 1.
First line
Second line at -e line 1.

Is it a normal behavior or not?
Re: Strange lines order for: exec or print "foo"; die "bar" [ In reply to ]
On Thu, Apr 29, 2021 at 10:36 AM ?????? ???????? <mchlkzch@gmail.com> wrote:

> When we use exec in form of: exec LIST or print "foo"; die "bar";
> it gives wrong (I guess) lines order in output subject to presence of
> "\n" in print statement:
>
> perl -E 'use warnings; exec "echo 1" or print "First line";
> die "Second line";'
> 1
>
> perl -E 'use warnings; exec "echos 1" or print "First line";
> die "Second line";'
> Can't exec "echos": No such file or directory at -e line 1.
> Second line at -e line 1.
> First line
>
> perl -E 'use warnings; exec "echos 1" or print "First line\n";
> die "Second line";'
> Can't exec "echos": No such file or directory at -e line 1.
> First line
> Second line at -e line 1.
>
> Is it a normal behavior or not?
>

Yes. You are observing the effects of line buffering. You can set $| to 1
to avoid this if you really want to.

Leon