Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Re: (crazyinsomniac)Re: Any way to binmode

by bikeNomad (Priest)
on Aug 02, 2001 at 16:02 UTC ( #101690=note: print w/replies, xml ) Need Help??


in reply to Re: Re: (crazyinsomniac)Re: Any way to binmode
in thread Any way to binmode <>

I know what you're saying, but it just doesn't work... this program:

use Data::Dumper; $Data::Dumper::Useqq = 1; FF: binmode ARGV; while(<>) { print Dumper($_) } continue { if(eof) { close ARGV; goto FF; } } __END__ this is ctrl-Z:^Z # note: real ctrl-Z there this is past ctrl-z

produces this output when run on itself under NT (line endings are \r\n):

/ned $ perl binmode.pl binmode.pl $VAR1 = "use Data::Dumper;\n"; $VAR1 = "\$Data::Dumper::Useqq = 1;\n"; $VAR1 = "\n"; $VAR1 = "FF: binmode ARGV;\n"; $VAR1 = "while(<>)\n"; $VAR1 = "{ print Dumper(\$_) }\n"; $VAR1 = "continue\n"; $VAR1 = "{ if(eof)\n"; $VAR1 = " { close ARGV; goto FF; }\n"; $VAR1 = "}\n"; $VAR1 = "__END__\n"; $VAR1 = "this is ctrl-Z:";

Replies are listed 'Best First'.
Re: Re: Re: Re: (crazyinsomniac)Re: Any way to binmode
by crazyinsomniac (Prior) on Aug 02, 2001 at 16:05 UTC
    It does indeed work, its your shell that is translating the newlines. Try redirecting to a file.

    update i'm wrong, i aplogize, but you can always:

    while(<>) { binmode ARGV; seek ARGV,0,0; local $/ $_=<>; }
    UPDATE: well i was almost there, this is kind of stupid, but it'll work as you want it to;
    while(<>) { close ARGV; open ARGV, $ARGV or die $!.' '.$ARGV; binmode ARGV; binmode ARGV; local $/; print $_=<>; close BINMODE; }

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

      How could my shell get the newlines? Look more closely... I used Data::Dumper so I could display the control characters in the output and so not be subject to output character translation. There's no difference in the output when I redirect to a file. Note that there is no output past the control-Z. If you're trying the script yourself, make sure to binmode STDOUT so that you don't turn "\n" back into "\r\n". And try a file with a control-Z in it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://101690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-05-17 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (167 votes). Check out past polls.

    Notices?