Removing whitespace and linebreaks in CSS files

Discussion in 'Perl Misc' started by ahjiang@gmail.com, Apr 11, 2006.

  1. Guest

    Hi all,

    Rather new to perl.

    Would like to know if there is any existing modules that remove
    whitespace and line breaks in cascading stylesheet files.

    Appreciate any inputs
    , Apr 11, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    wrote:

    > Rather new to perl.


    http://learn.perl.org is a good place to start
    Also, run `perldoc perlintro` on your command line to get an
    introduction to the language.

    > Would like to know if there is any existing modules that remove
    > whitespace and line breaks in cascading stylesheet files.


    That problem is too simplistic for an entire module. It's one line of
    code.

    s/\s{2,}|\n/ /g for @lines;

    That will go through all lines contained in @lines, and replace any
    sequences of more than one whitespace, and all newlines, with a single
    space. It is a trivial matter both to open the file and get its
    content into @lines, and another trivial matter to print the modified
    @lines to the file.

    perldoc perlopentut
    for both.

    Paul Lalli
    Paul Lalli, Apr 11, 2006
    #2
    1. Advertising

  3. Guest

    thanks for the advice..will look into it..

    u really amaze me with the single line code!!!

    Paul Lalli wrote:
    > wrote:
    >
    > > Rather new to perl.

    >
    > http://learn.perl.org is a good place to start
    > Also, run `perldoc perlintro` on your command line to get an
    > introduction to the language.
    >
    > > Would like to know if there is any existing modules that remove
    > > whitespace and line breaks in cascading stylesheet files.

    >
    > That problem is too simplistic for an entire module. It's one line of
    > code.
    >
    > s/\s{2,}|\n/ /g for @lines;
    >
    > That will go through all lines contained in @lines, and replace any
    > sequences of more than one whitespace, and all newlines, with a single
    > space. It is a trivial matter both to open the file and get its
    > content into @lines, and another trivial matter to print the modified
    > @lines to the file.
    >
    > perldoc perlopentut
    > for both.
    >
    > Paul Lalli
    , Apr 12, 2006
    #3
  4. robic0 Guest

    On 11 Apr 2006 07:00:47 -0700, "Paul Lalli" <> wrote:

    > wrote:
    >
    >> Rather new to perl.

    >
    >http://learn.perl.org is a good place to start
    >Also, run `perldoc perlintro` on your command line to get an
    >introduction to the language.
    >
    >> Would like to know if there is any existing modules that remove
    >> whitespace and line breaks in cascading stylesheet files.

    >
    >That problem is too simplistic for an entire module. It's one line of
    >code.
    >
    >s/\s{2,}|\n/ /g for @lines;


    s/\s/g will remove all
    \s is a whitespace character and represents [\ \t\r\n\f]
    is that what you want, or do you know what you want?
    robic0, Apr 12, 2006
    #4
  5. Paul Lalli Guest

    robic0 wrote:
    > s/\s/g will remove all


    That will not remove anything. It will not do anything but generate a
    compiler error.

    > \s is a whitespace character and represents [\ \t\r\n\f]
    > is that what you want, or do you know what you want?


    Why are you talking to the OP in a reply to my message?

    Paul Lalli
    Paul Lalli, Apr 12, 2006
    #5
  6. Guest

    sorry can u briefly explain what this line does?

    s/\s{2,}|\n/ /g for @lines;

    for all the lines...
    s/\s{2,}|\n/ /g ??????
    , Apr 12, 2006
    #6
  7. Guest Guest

    wrote:
    : sorry can u briefly explain what this line does?

    : s/\s{2,}|\n/ /g for @lines;

    ^ s=substitute /value/replacement/

    Replaces value found by a replacement; the final g means "global", all
    occurrences in searched data.

    You look for a value defined as \s{2,}|\n which reads as:
    every occurrence of whitespace (= \s) which is at least
    two characters long, and has no defined upper limit (={2,}),
    or, alternatively, (= | ), a newline (= \n).

    Your replacement is a single space.
    : for all the lines...
    : s/\s{2,}|\n/ /g ??????

    Check the perlre manpage.

    Oliver.
    --
    Dr. Oliver Corff e-mail: -berlin.de
    Guest, Apr 12, 2006
    #7
  8. Guest

    apperciate ur help..

    guess there is still a lot for me to learn!
    , Apr 12, 2006
    #8
  9. Anno Siegel Guest

    Paul Lalli <> wrote in comp.lang.perl.misc:
    > wrote:
    >
    > > Rather new to perl.

    >
    > http://learn.perl.org is a good place to start
    > Also, run `perldoc perlintro` on your command line to get an
    > introduction to the language.
    >
    > > Would like to know if there is any existing modules that remove
    > > whitespace and line breaks in cascading stylesheet files.

    >
    > That problem is too simplistic for an entire module. It's one line of
    > code.
    >
    > s/\s{2,}|\n/ /g for @lines;


    That's exactly what tr///'s squeeze-option does:

    tr/ \n/ /s for @lines;

    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.
    Anno Siegel, Apr 12, 2006
    #9
  10. Paul Lalli Guest

    Anno Siegel wrote:
    > Paul Lalli <> wrote in comp.lang.perl.misc:
    > > s/\s{2,}|\n/ /g for @lines;

    >
    > That's exactly what tr///'s squeeze-option does:
    >
    > tr/ \n/ /s for @lines;


    Dang it. I *knew* there was a cleaner way to write that, but it wasn't
    coming to me. I always manage to forget about tr///. Thanks, Anno.

    Paul Lalli
    Paul Lalli, Apr 12, 2006
    #10
  11. Anno Siegel wrote:
    > Paul Lalli <> wrote in comp.lang.perl.misc:
    >> wrote:
    >>
    >>>Rather new to perl.

    >>http://learn.perl.org is a good place to start
    >>Also, run `perldoc perlintro` on your command line to get an
    >>introduction to the language.
    >>
    >>>Would like to know if there is any existing modules that remove
    >>>whitespace and line breaks in cascading stylesheet files.

    >>That problem is too simplistic for an entire module. It's one line of
    >>code.
    >>
    >>s/\s{2,}|\n/ /g for @lines;

    >
    > That's exactly what tr///'s squeeze-option does:
    >
    > tr/ \n/ /s for @lines;


    Don't forget the other characters in \s:

    tr/ \f\t\r\n/ /s for @lines;


    :)

    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Apr 12, 2006
    #11
  12. Anno Siegel Guest

    John W. Krahn <> wrote in comp.lang.perl.misc:
    > Anno Siegel wrote:
    > > Paul Lalli <> wrote in comp.lang.perl.misc:
    > >> wrote:
    > >>
    > >>>Rather new to perl.
    > >>http://learn.perl.org is a good place to start
    > >>Also, run `perldoc perlintro` on your command line to get an
    > >>introduction to the language.
    > >>
    > >>>Would like to know if there is any existing modules that remove
    > >>>whitespace and line breaks in cascading stylesheet files.
    > >>That problem is too simplistic for an entire module. It's one line of
    > >>code.
    > >>
    > >>s/\s{2,}|\n/ /g for @lines;

    > >
    > > That's exactly what tr///'s squeeze-option does:
    > >
    > > tr/ \n/ /s for @lines;

    >
    > Don't forget the other characters in \s:
    >
    > tr/ \f\t\r\n/ /s for @lines;


    Ah, I misread the code somehow and thought it only did blank and line feed.

    That is the one drawback of tr/// that you must expand \s yourself to be
    as general as s///.

    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.
    Anno Siegel, Apr 12, 2006
    #12
    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. Oli Filth
    Replies:
    9
    Views:
    3,313
    Uncle Pirate
    Jan 17, 2005
  2. =?ISO-8859-15?Q?Martin_K=F6rner?=

    email: Content-Disposition and linebreaks with long filenames

    =?ISO-8859-15?Q?Martin_K=F6rner?=, Apr 13, 2005, in forum: Python
    Replies:
    2
    Views:
    3,485
    David Bolen
    Apr 19, 2005
  3. allie

    empty P tags and linebreaks

    allie, Nov 2, 2006, in forum: HTML
    Replies:
    4
    Views:
    563
    Bergamot
    Nov 3, 2006
  4. Replies:
    10
    Views:
    717
    Eric Brunel
    Dec 16, 2008
  5. MRAB
    Replies:
    3
    Views:
    368
Loading...

Share This Page