- #!/usr/bin/perl
- # This script translates white space to tabs,
- # if they come in groups of four. It takes one argument: 'text file'.
- use 5.14.0;
- use strict;
- use warnings;
- my($infile, @content);
- my $tab = ' {4}';
- if (!$ARGV[0] || !-T $ARGV[0]) {
- say "Usage: " . basename($0) . " [ text file ]";
- exit;
- } else { $infile = $ARGV[0]; }
- @content = `cat '$infile'`;
- my($match) = $content[$n] =~ /^( +)/; # Find lines that start with
- if ($match) { # spaces.
- my $write = $match;
- $write =~ s/($tab)/\t/g; # Translate individual spaces to tabs.
- $content[$n] =~ s/^$match/$write/;
- }
- }
spaces 2 tabs, source code
Posted by Anonymous on Thu 20th Sep 2012 04:43
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.