binmode in 1-liner?

Discussion in 'Perl Misc' started by Larry, Jan 16, 2006.

  1. Larry

    Larry Guest

    I am a big fan of Perl 1-liners and I even use them on Windows. One
    thing that bugs me though is that there doesn't seem to be an easy way
    to process binary files with 1 liners. It would be nice if there were
    a command-line switch to turn on "binmode". As it is, I am forced to
    use

    perl -0777 -ne "BEGIN { binmode STDIN; binmode STDOUT } ... "

    which is a lot of typing for a 1-liner.
     
    Larry, Jan 16, 2006
    #1
    1. Advertising

  2. Larry

    Dr.Ruud Guest

    Larry:

    > I am a big fan of Perl 1-liners and I even use them on Windows. One
    > thing that bugs me though is that there doesn't seem to be an easy way
    > to process binary files with 1 liners. It would be nice if there were
    > a command-line switch to turn on "binmode". As it is, I am forced to
    > use
    >
    > perl -0777 -ne "BEGIN { binmode STDIN; binmode STDOUT } ... "
    >
    > which is a lot of typing for a 1-liner.


    Use a wrapper.

    Maybe call it 'perlb.pl' (assumes you have added 'pl' to the executable
    extensions).

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Jan 16, 2006
    #2
    1. Advertising

  3. Larry wrote:
    > I am a big fan of Perl 1-liners and I even use them on Windows. One
    > thing that bugs me though is that there doesn't seem to be an easy way
    > to process binary files with 1 liners. It would be nice if there were
    > a command-line switch to turn on "binmode". As it is, I am forced to
    > use
    >
    > perl -0777 -ne "BEGIN { binmode STDIN; binmode STDOUT } ... "
    >
    > which is a lot of typing for a 1-liner.
    >


    You can set the environment variable PERLIO to accomplish this. see

    perldoc perlrun

    for details.

    Not quite the same, of course.

    The other alternative would be to create a module that does the
    necessary in its BEGIN block. You could then

    perl -MMyBinModeModule -le "...........

    though probably choosing a shorter name for the module.

    Mark
     
    Mark Clements, Jan 16, 2006
    #3
  4. Larry

    Anno Siegel Guest

    Mark Clements <> wrote in comp.lang.perl.misc:
    > Larry wrote:
    > > I am a big fan of Perl 1-liners and I even use them on Windows. One
    > > thing that bugs me though is that there doesn't seem to be an easy way
    > > to process binary files with 1 liners. It would be nice if there were
    > > a command-line switch to turn on "binmode". As it is, I am forced to
    > > use
    > >
    > > perl -0777 -ne "BEGIN { binmode STDIN; binmode STDOUT } ... "
    > >
    > > which is a lot of typing for a 1-liner.
    > >

    >
    > You can set the environment variable PERLIO to accomplish this. see
    >
    > perldoc perlrun
    >
    > for details.
    >
    > Not quite the same, of course.
    >
    > The other alternative would be to create a module that does the
    > necessary in its BEGIN block. You could then


    If it's a module, the BEGIN {} doesn't make a difference. If it's
    loaded via "use", it will be run at compile time (relative to the
    calling script) anyway. If it's via "require", BEGIN {} in the module
    doesn't help any.

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Jan 17, 2006
    #4
  5. Anno Siegel wrote:
    > Mark Clements <> wrote in comp.lang.perl.misc:
    >> Larry wrote:
    >>> I am a big fan of Perl 1-liners and I even use them on Windows. One
    >>> thing that bugs me though is that there doesn't seem to be an easy way
    >>> to process binary files with 1 liners. It would be nice if there were
    >>> a command-line switch to turn on "binmode". As it is, I am forced to
    >>> use
    >>>
    >>> perl -0777 -ne "BEGIN { binmode STDIN; binmode STDOUT } ... "
    >>>
    >>> which is a lot of typing for a 1-liner.
    >>>

    >> You can set the environment variable PERLIO to accomplish this. see
    >>
    >> perldoc perlrun
    >>
    >> for details.
    >>
    >> Not quite the same, of course.
    >>
    >> The other alternative would be to create a module that does the
    >> necessary in its BEGIN block. You could then

    >
    > If it's a module, the BEGIN {} doesn't make a difference. If it's
    > loaded via "use", it will be run at compile time (relative to the
    > calling script) anyway. If it's via "require", BEGIN {} in the module
    > doesn't help any.
    >


    OK: I should have thought of this. Thanks for the correction.

    Mark
     
    Mark Clements, Jan 17, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dmitry Borodaenko

    StringIO#binmode: bug in cgi.rb and yaml.rb

    Dmitry Borodaenko, Aug 20, 2003, in forum: Ruby
    Replies:
    2
    Views:
    187
    Nobuyoshi Nakada
    Aug 23, 2003
  2. Henning Koch

    pstore.rb not operating in binmode

    Henning Koch, Oct 4, 2004, in forum: Ruby
    Replies:
    4
    Views:
    135
    Henrik Horneber
    Oct 5, 2004
  3. J. Romano

    binmode and the diamond operator

    J. Romano, Nov 8, 2003, in forum: Perl Misc
    Replies:
    6
    Views:
    198
    J. Romano
    Nov 17, 2003
  4. Alain Star
    Replies:
    1
    Views:
    281
    Brian McCauley
    Dec 13, 2004
  5. dearcilla

    binmode clobbers :via

    dearcilla, Aug 1, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    99
Loading...

Share This Page