in reply to Re: formatting newline characters
in thread formatting newline characters

No, the problem is that I really need to keep them but as newlines - Access keeps effectively ignoring them by converting them to boxes. The reason for the substitution was that I was told that Access might prefer \r\n to \n, but this doesn't seem to be the case. Thanks anyway.

Replies are listed 'Best First'.
(z) Re: Re: Re: formatting newline characters
by zigdon (Deacon) on Nov 05, 2002 at 16:29 UTC

    It's true that access prefers \r\n, but only if you're on a unix. On windows, access prefers the \n. The reason for the confusion is that \n isn't really a character, it's a LOGICAL newline. From perlport:

    Perl uses "\n" to represent the "logical" newline, where what is logical may depend on the platform in use. In MacPerl, "\n" always means "\015". In DOSish perls, "\n" usually means "\012", but when accessing a file in "text" mode, STDIO translates it to (or from) "\015\012", depend- ing on whether you're reading or writing. Unix does the same thing on ttys in canonical mode. "\015\012" is com- monly referred to as CRLF.

    So in order to fix unix newlines to dos newlines, you need to ADD a LF to the end of lines:

    my $LF = "\012"; while (<>) } s/$/$LF/g; }

    -- Dan

Re: Re: Re: formatting newline characters
by FamousLongAgo (Friar) on Nov 05, 2002 at 16:20 UTC
    Try using the s flag on your regular expression, to match multiple lines. The regex you are now using will not match newlines - it stops at the first one.
    $input =~ s/\n/\r\n/gs;
    Also, you might try some sanity checks:
    print "contains CR's!\n" if $input=~/\r/s; print "contains NL's!\n" if $input=~/\n/s; ...
    Good luck!
Re: Re: Re: formatting newline characters
by Anonymous Monk on Nov 05, 2002 at 17:09 UTC
    Access uses a font(really a control method) where \n (really all control characters) look like a box. So access stores your \n correctly and there is no way to show two lines, which you evidently want.
      Thought I'd share a solution I have (FINALLY!!) found in case other people had experienced the same problem: If you have a text area field where the newlines are being ignored and showing up as little boxes, right click in the text area box then click on properties. Select the Format tab then scroll down to Numerical Shapes. Change this from System to Context and all the newlines reappear making your data finally make sense! Not really a Perl solution but it works so who cares!