Text::Wrap::wrap difference

Discussion in 'Perl Misc' started by Art Werschulz, Sep 24, 2003.

  1. Hi.

    # Article reposted ... I cancelled it when I thought I had figured out
    # the answer ...

    I have moved from a Solaris box (running perl 5.6.0) to an Intel Linux
    box (running perl 5.8.0).

    I have a script that processes msgs I get from certain mailing lists
    (which procmail kindly puts into files for me). It wordwraps the msgs
    (since some of them have ridiculously long lines) and replaces certain
    encoded chars by their plain text equivalents. It looks like this

    %<------%<--%<--%<---cut here---%<--%<--%<----------------------------
    use Text::Wrap;

    $Text::Wrap::columns = 79;

    while (<>) {
    s/\c]/\"/g;
    s/\cA//g;
    s/\cS/--/g;
    s/\cY/\'/g;
    s/=$//;
    s/=20//;
    s/=85/.../g;
    s/=91/\'/g;
    s/=92/\'/g;
    s/=93/\"/g;
    s/=94/\"/g;
    s/=96/--/g;
    s/\205/.../g;
    s/\221/\'/g;
    s/\222/\'/g;
    s/\223/\"/g;
    s/\224/\"/g;
    s/\226/--/g;
    s/\227/.../g;
    s/\255/--/g;
    $_ = wrap("", "", $_) unless /^[^\s]+:\s/;
    print $_;
    }
    %<------%<--%<--%<---cut here---%<--%<--%<----------------------------

    I want blank lines to remain in the text. When running this script on
    the Solaris box, the blank lines are maintained. However, they
    disappear if I run this script on the Linux box.

    Why the difference between these platforms? Has something changed
    between versions 5.6 and 5.8?

    I would appreciate suggestions for making this work on the Linux box.

    Thanks.

    --
    Art Werschulz (8-{)} "Metaphors be with you." -- bumper sticker
    GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y?
    Internet: <a href="http://www.cs.columbia.edu/~agw/">WWW</a>
    ATTnet: Columbia U. (212) 939-7060, Fordham U. (212) 636-6325
     
    Art Werschulz, Sep 24, 2003
    #1
    1. Advertising

  2. Art Werschulz

    Anno Siegel Guest

    Art Werschulz <> wrote in comp.lang.perl.misc:
    > Hi.
    >
    > # Article reposted ... I cancelled it when I thought I had figured out
    > # the answer ...
    >
    > I have moved from a Solaris box (running perl 5.6.0) to an Intel Linux
    > box (running perl 5.8.0).
    >
    > I have a script that processes msgs I get from certain mailing lists
    > (which procmail kindly puts into files for me). It wordwraps the msgs
    > (since some of them have ridiculously long lines) and replaces certain
    > encoded chars by their plain text equivalents. It looks like this
    >
    > %<------%<--%<--%<---cut here---%<--%<--%<----------------------------
    > use Text::Wrap;
    >
    > $Text::Wrap::columns = 79;
    >
    > while (<>) {
    > s/\c]/\"/g;
    > s/\cA//g;
    > s/\cS/--/g;
    > s/\cY/\'/g;
    > s/=$//;
    > s/=20//;
    > s/=85/.../g;
    > s/=91/\'/g;
    > s/=92/\'/g;
    > s/=93/\"/g;
    > s/=94/\"/g;
    > s/=96/--/g;
    > s/\205/.../g;
    > s/\221/\'/g;
    > s/\222/\'/g;
    > s/\223/\"/g;
    > s/\224/\"/g;
    > s/\226/--/g;
    > s/\227/.../g;
    > s/\255/--/g;
    > $_ = wrap("", "", $_) unless /^[^\s]+:\s/;
    > print $_;
    > }
    > %<------%<--%<--%<---cut here---%<--%<--%<----------------------------
    >
    > I want blank lines to remain in the text. When running this script on
    > the Solaris box, the blank lines are maintained. However, they
    > disappear if I run this script on the Linux box.
    >
    > Why the difference between these platforms? Has something changed
    > between versions 5.6 and 5.8?


    I don't see anything in your s/// that would be subject to a version
    change. Could the behavior of Text::Wrap have changed? wrap() is
    only advertised as a paragraph formatter, which makes it rather uncommitted
    to empty lines.

    If it's not that, it must be some unicode devilry. That works well
    as an explanation of the inexplicable.

    The substitution sequence could be greatly simplified. Most are single-
    character substitutions, a single tr/// can do them all. Some are character
    deletions, which another tr/// can do. What remains are substitutions
    of single characters with either "--" or "...". Two s/// with character
    classes on the regex side can do those.

    >
    > I would appreciate suggestions for making this work on the Linux box.


    Deal with empty lines explicitly. I don't know Text::Wrap very well,
    but they do mark an end-of-paragraph. Someone who does know Text::Wrap
    may have a better idea.

    Anno
     
    Anno Siegel, Sep 25, 2003
    #2
    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. jakk
    Replies:
    4
    Views:
    12,217
  2. walterbyrd
    Replies:
    7
    Views:
    313
    Asun Friere
    May 17, 2007
  3. Aaron Fude

    To wrap or not to wrap?

    Aaron Fude, May 8, 2008, in forum: Java
    Replies:
    12
    Views:
    700
    Chronic Philharmonic
    May 10, 2008
  4. Art Werschulz

    Text::Wrap::wrap difference

    Art Werschulz, Sep 22, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    232
    Art Werschulz
    Sep 22, 2003
  5. Nick Timkovich
    Replies:
    0
    Views:
    69
    Nick Timkovich
    Feb 25, 2014
Loading...

Share This Page