in reply to a newbie's output reversed
print "In binary, that is "; while ($x < 8) { @binary[$x]=1; print @binary[$x]; $x++; } die"\n\nProgram ended successfully";
The warning means that @binary[$x] = 1; should be written as $binary[$x] = 1;
The reverse order comes from buffering. die writes to a different buffer (STDERR) than regular prints (which write to STDOUT). In fact, STDERR is unbuffered by default, and STDOUT is line-buffered by default. That is, everything you print to STDERR is immediately shown on screen, while everything to STDOUT will not show up on the screen until a line break is printed.
To end a program "successfully," you should not use die. Instead, you should print whatever you wanted to with print and then exit(0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: a newbie's output reversed
by Anonymous Monk on Dec 14, 2011 at 08:59 UTC |