I got a file where tabs are 8 chars and I want to revert them to 4 chars.
Actually, you don't. A tab isn't a certain number of spaces, it's a tab. Various text editors/word processors will represent the tab as a number of spaces. Depending on your settings, they may actually save (X) spaces when you hit tab, rather than save the tab.
Generally you want to convert tabs to spaces or spaces to tabs. My attempt to do what I think you mean is to either:
- Change the configuration on your text editor to set tabs as 4 spaces OR,
- do a regex to replace \t with " "
Assuming you are interested in the regex, here's a quick-and-dirty try:
while (<>){
s/\t/ /g;
}
Or to reverse it:
while (<>){
s/ /\t/g;
}
Note that reversing it isn't an actual reversal....it replaces all sequences of spaces with tabs, even if they weren't originally a tab.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.