pl@nereida:~/Lperltesting$ cat -n expandtabs.pl 1 #!/usr/bin/perl -w 2 use strict; 3 4 my @string = <>; 5 6 for (@string) { 7 while (s/\t+/' ' x (length($&)*8 - length($`)%8)/e) {} 8 print $_; 9 }Sigue un ejemplo de ejecución:
pl@nereida:~/Lperltesting$ cat -nt tabs.in 1 012345670123456701234567012345670 2 one^Itwo^I^Ithree 3 four^I^I^I^Ifive 4 ^I^Itwo pl@nereida:~/Lperltesting$ ./expandtabs.pl tabs.in | cat -tn 1 012345670123456701234567012345670 2 one two three 3 four five 4 two
while
por una opción /g
?
pl@nereida:~/Lperltesting$ cat -n ./expandtabs2.pl 1 #!/usr/bin/perl -w 2 use strict; 3 4 my @string = <>; 5 6 for (@string) { 7 s/\t+/' ' x (length($&)*8 - length($`)%8)/ge; 8 print $_; 9 }¿Porqué?