I’m using the following perl expression to remove tabs from here
$text =~ s{(.*?)\t}{$1.(' ' x ($g_tab_width - length($1) % $g_tab_width))}ge;
I’ve simplified my understanding and translation down to the following (assuming a tab width of four spaces)
$text =~ s/(.*?)\t/' '/;
but I feel like I’ve broken Einstein’s instruction
Make things as simple as possible, but not simpler.
I’m testing with the following input strings.
"\t \t"
"\t\t \t"
"\t\t \t\t \t"
"\t\t \t\t \t"
Can someone demonstrate an input string that would give inconsistent results between these two? (within the problem space of removing tabs)
I’ll assume that your second simplified expression is supposed to be:
and that
$g_tab_widthis four; nothing else would make sense to me here so I’ll live dangerously and assume that things are supposed to make sense.Given that, almost anything with tabs will produce different results. For example:
Produces these results:
Live version: http://ideone.com/LbnNx
The only time they’ll both produce the same result is when your non-tab components are all 4*n characters long, for example:
Live version: http://ideone.com/Kvp3l