|
|
|
good chemistry is complicated, and a little bit messy -LW |
|
| PerlMonks |
Re: regex'ing source codeby muba (Curate) |
| on Jun 29, 2012 at 00:38 UTC ( #979024=note: print w/ replies, xml ) | Need Help?? |
|
It's not that complex. Just split your lines on tab characters, using split( /(\t)/, $line ). Those parens around \t make sure the tabs themself will be included in the elements of split, too. From there on, it's simple: print out every piece that's not a tab character, and keep track of how many characters you've printed so far. If you eventually do run into a tab character, you just print enough spaces to end up at a tab boundary. To make sure things keep running smoothly, you want to make sure that those spaces also count for the number of characters printed so far. Still sounds complicated? This is all it takes.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||