in reply to Perl 5.8, sockets and binmode()

How about (untested!) something like this for clarity:
BEGIN { eval "require 5.008; use open OUT => ':raw:perlio'; sub _binmode() + {}"; eval "sub _binmode { binmode @_ }" if $@; }
Then replace the binmode with _binmode and everything should happen automagically. The prototype will even cause these calls to be optimized away complete on Perls that don't need them.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Perl 5.8, sockets and binmode()
by Jenda (Abbot) on Nov 06, 2002 at 20:31 UTC

    I guess I could redefine the binmode(). I can't use the sub binmode () {} though ... keep in mind that the procedure gets some parameters. So it can't be optimized away. It's a shame the $] is not treated as a constant. If it was then the binmode(...) unless $] < 5.008 could be optimized away. Not that it matters.

    But the use open ... within the eval "" doesn't work. The use open pragma seems to be lexical if used this way. That's why am I using the require() and 'open'->import().

    Jenda

      Ah, but you can retrofit that.
      use constant PRE_5_8 => $[ < 5.008; binmode $fh if PRE_5_8;
      You can also use the constant for the BEGIN block if you are so inclined, of course (provided you define it before the block).

      Makeshifts last the longest.