GrandFather has asked for the wisdom of the Perl Monks concerning the following question:
In the following code:
use strict; use warnings; sub foo {return 'foo';} die "No bar here" if bar () ne 'bar'; print foo () . "\n"; print bar () . "\n"; sub bar {return 'bar';}
I get the following output:
Unquoted string "bar" may clash with future reserved word at noname.pl + line 8. foo Use of uninitialized value in concatenation (.) or string at noname.pl + line 8. print() on unopened filehandle bar at noname.pl line 8.
The text foo is sent to stdout, the remainder is sent to stderr. Note that the die isn't executed.
If I change the print bar to print '' . bar then I get the output I expect without error messages. What is going on here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wierd print and sub ordering problem
by rinceWind (Monsignor) on Oct 30, 2005 at 11:24 UTC | |
|
Re: Wierd print and sub ordering problem
by ioannis (Abbot) on Oct 30, 2005 at 12:01 UTC |