I wrote:
>> $| = 1; # [1] $OUTPUT_AUTOFLUSH
On 05/08/13 02:24, Shlomi Fish wrote:
http://perl-begin.org/tutorials/bad-elements/#properly_autoflushing
Which recommends:
use IO::Handle;
STDOUT->autoflush(1);
1. For larger, longer-lived, shared, portable, "serious", "Modern
Perl", etc., programs, that way is better.
2. I saw the OP's requirements as being met by a short "throw-away"
script that wouldn't be kept or distributed. $| is fast and cheap, and
it works.
3. Part of gaining proficiency in Perl (and other Unix tools) is
learning the more commonly used special variables, such as $|, $?, $@, etc..
4. Autoflush might not be needed in this case. I put it in there as a
reminder for scripts that do need it.
print `cat *>>foo.out`; # [2] qx//
This is the same as «system('cat *>> foo.out')» (only more costly), and the
command in this case should not emit any output (because it is redirected to a
file).
1. I thought about:
if (my $e = system('cat * >> foo.out')) {
# error handling
}
But, a decent system() example should use the multi-argument list form.
That means I would have to redirect STDOUT first and glob the file
names in the argument list. Too much complexity for a "beginner" posting.
2. Yes, cat's STDOUT ends up in foo.out and STDERR ends up on the
console. I put the "print" in there as much to make people say "WTF?",
look it up, and ponder it, thus reinforcing their knowledge of backticks.
3. The append redirect ">>" is a bug/ mis-feature -- foo.out will grow
every time the script is run, The user is required to delete foo.out
manually before running the script. The alternative, ">", destroys
data. Pick your poison.
> Furthermore, many non-UNIX-like systems don't contain a cat command.
Thank God for electronics recycling. ;-)
David
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/