On DOSish systems sometimes a problem arises with "\r\n" versus "\n" lineending, and I sometimes found myself typing from command line
perl -we "binmode STDOUT;do{'something'};>xx.txt" sometimes "binmode STDIN" is also needed.

With a help of a simpliest module "b.pm" I can always write now perl -mb -we "do {'something'};" and have possibility to save priceless characters on a command line :)
Just put it in @INC as "b.pm" and then use additinal -mb command line argument.

# the only need of this module file is to ease binmode'ing # for STDIN, STDOUT, so one could write # perl -mb -we "'do-something, and STDxxx are in binmode'" sub BEGIN { binmode STDIN; binmode STDOUT; } 1;
simple example of usage is just: perl -mb -wn0777e "s/\r//g;print" file.txt >file.out which will strip \r from file.txt

Replies are listed 'Best First'.
•Re: ease binmode STDIN; binmode STDOUT
by merlyn (Sage) on May 16, 2002 at 20:50 UTC
    The sub BEGIN, which is a perverse way of simply writing a BEGIN block, is completely unnecessary, and obfuscates this code needlessly. Just a simple version will do:
    binmode STDIN; binmode STDOUT; 1;

    -- Randal L. Schwartz, Perl hacker

      you're right.

      When I inserted a code I thought "is that BEGIN really necessary" but decided to insert code as it was in my file, although it can be reduced.

      Vadim.

Re: ease binmode STDIN; binmode STDOUT
by Courage (Parson) on May 30, 2002 at 20:32 UTC
    unfortunately b.pm clashes with B.pm from standard distribution, so it's much better to name in other way, say, c.pm.