creating unix-like text files in windows

Discussion in 'Perl Misc' started by Huppu, Nov 25, 2003.

  1. Huppu

    Huppu Guest

    Hi!

    I'm trying to create unix-like text files in Windows. The biggest issue is
    that I need to use only linefeed instead of carriage return+linefeed. It
    tried this with hex value \x0A, but it still did norman windows linebreak
    LF+CR(like I was using \n).

    Does anyone have any solution for this? Creating these files in unix is not
    a solution... ;-)

    <-_->
    Huppu, Nov 25, 2003
    #1
    1. Advertising

  2. Huppu

    Pedro Graca Guest

    Huppu wrote:
    > I'm trying to create unix-like text files in Windows. The biggest issue is
    > that I need to use only linefeed instead of carriage return+linefeed. It
    > tried this with hex value \x0A, but it still did norman windows linebreak
    > LF+CR(like I was using \n).
    >
    > Does anyone have any solution for this? Creating these files in unix is not
    > a solution... ;-)


    newbie answer -- probably gurus have a better way to do it

    check binmode
    perldoc -f binmode

    example program
    #!/usr/bin/perl -w
    use strict;

    open my $FILE, ">unix.txt" or die $!;
    binmode $FILE;

    print $FILE "one\n";
    print $FILE "two\n";
    print $FILE "three\n";
    print $FILE "four\n";
    print $FILE "five\n";
    close $FILE;



    HTH

    --
    ..sig
    Pedro Graca, Nov 25, 2003
    #2
    1. Advertising

  3. Hi Huppu,

    By default, the translation from LF to CRLF happens in the IO layer.

    You turn it off like this:

    binmode FILEHANDLE;

    Or by specifying binary mode when opening, which is a better idea.

    For more information:
    perldoc -f binmode
    perldoc -f open
    perldoc -f sysopen

    perldoc IO::File
    perldoc PerlIO

    Cheers,
    Ben Liddicott


    "Huppu" <> wrote in message news:...
    > Hi!
    >
    > I'm trying to create unix-like text files in Windows. The biggest issue is
    > that I need to use only linefeed instead of carriage return+linefeed. It
    > tried this with hex value \x0A, but it still did norman windows linebreak
    > LF+CR(like I was using \n).
    Ben Liddicott, Nov 25, 2003
    #3
  4. Huppu

    Huppu Guest

    binmode helped, thank you for advices.

    <-_->
    Huppu, Nov 27, 2003
    #4
    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. Koo
    Replies:
    1
    Views:
    495
    David Harmon
    Jan 30, 2004
  2. Jonathan Fine
    Replies:
    4
    Views:
    840
    Jonathan Fine
    Mar 2, 2005
  3. Replies:
    3
    Views:
    1,275
    Walter Roberson
    May 1, 2006
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    455
    Patrick Kowalzick
    Mar 14, 2006
  5. Replies:
    2
    Views:
    153
    Tad McClellan
    Mar 22, 2005
Loading...

Share This Page