Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Cleaning Whitespace from Source Code

by Prior Nacre V (Hermit)
on Dec 09, 2004 at 08:55 UTC ( #413455=note: print w/replies, xml ) Need Help??


in reply to Cleaning Whitespace from Source Code

As already stated above, it is unclear exactly what you trying to achieve.

The following is probably too simplistic as a complete solution but the two methods described may be useful in parts of your final script.

  • $/ is used here to remove duplicate blank lines
  • y/// (alias tr///) is used here to remove duplicate spaces

(These are not their only uses.)

[ ~/tmp ] $ cat spacey_text 1 12 23 32 21 1 a b c d e 1 blank: 2 blanks: 3 blanks: end_blanks [ ~/tmp ] $ perl -we 'use strict; { local $/ = ""; while (<>) { $_ =~ +y/ / /s; print $_; } }' spacey_text 1 12 23 32 21 1 a b c d e 1 blank: 2 blanks: 3 blanks: end_blanks [ ~/tmp ] $

Regards,

PN5

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-05-28 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (98 votes). Check out past polls.

    Notices?