#!/usr/bin/perl -w # Copyright (C) 2005 Marcel Meckel # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # tab2space.pl 0.0.1 # converts tabs to spaces "the right way" # no stupid \t => fixed $x spaces translation # # example: # ./tab2space.pl < filename > filename2 use strict; use warnings; my $tabsize = 8; my $space; my $spaces; while () { while ($_ =~ /\t/g) { my $pos = pos($_); if ($pos % $tabsize == 0) { $spaces = 1; } else { $spaces = $tabsize - ($pos % $tabsize) + 1; } # if .. else $space = " "x$spaces; $_ =~ s/\t/$space/; } # while print $_; } exit 0;