Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > binmode in 1-liner?

Reply
Thread Tools

binmode in 1-liner?

 
 
Larry
Guest
Posts: n/a
 
      01-16-2006
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.

 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      01-16-2006
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."

 
Reply With Quote
 
 
 
 
Mark Clements
Guest
Posts: n/a
 
      01-16-2006
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
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      01-17-2006
Mark Clements <(E-Mail Removed)> 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.
 
Reply With Quote
 
Mark Clements
Guest
Posts: n/a
 
      01-17-2006
Anno Siegel wrote:
> Mark Clements <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
binmode clobbers :via dearcilla Perl Misc 1 08-01-2005 03:35 PM
Sending a binary file through a script (binmode/stdout/mime type) Alain Star Perl Misc 1 12-13-2004 12:29 PM
pstore.rb not operating in binmode Henning Koch Ruby 4 10-05-2004 09:07 AM
binmode and the diamond operator J. Romano Perl Misc 6 11-17-2003 02:47 AM
StringIO#binmode: bug in cgi.rb and yaml.rb Dmitry Borodaenko Ruby 2 08-22-2003 11:46 PM



Advertisments