Hi David,

On Wed, 08 May 2013 19:37:30 -0700
David Christensen <dpchr...@holgerdanske.com> wrote:

> 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.
> 

Yes, and obscure.

> 3.  Part of gaining proficiency in Perl (and other Unix tools) is 
> learning the more commonly used special variables, such as $|, $?, $@, etc..

And an even further part of gaining proficiency is to know to make your code
less obscure and less clever and more
http://en.wikipedia.org/wiki/KISS_principle (not my own link!).

> 
> 4.  Autoflush might not be needed in this case.  I put it in there as a 
> reminder for scripts that do need it.
> 

OK.

> 
> >>    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.

Nothing wrong with a non-list call to system() if that is what you want and need
(as long as you say why you intend to do that and use precautions such as
https://metacpan.org/release/String-ShellQuote ). Doing «print `...`» is silly.

> 
> 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.

Please don't give people "WTF?" moments like that. I am an experienced
programmer and your code gave me that.

> 
> 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.

Yes.

>  > Furthermore, many non-UNIX-like systems don't contain a cat command.
> 
> Thank God for electronics recycling.  ;-)
> 

What do you mean?

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

George: I guess you can enter now. I’m just following orders.
SGlau: The Nuremberg defense!
George: This place gives you no other option.
    — http://www.shlomifish.org/humour/Summerschool-at-the-NSA/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to