[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Curious behaviour in Text::Tabs



Hello All,

I've been working on some scripts where I need to faithly replace <tab>'s with
<space>'s and vice-versa in files that are being processed.

Is it just me, or is there something a bit wrong with the Text::Tabs module?
At first glance this ought to be a trivial task, but there is a bit more to
this than first meets the eye...

Try the following script with the text file and observe the output.  The text
file has embedded <tab>'s with a tabstop of 4.  The last section of this  
message is a partial output that I get.

If you use an editor like BBEdit (show invisibles), you can see what I mean.

What I expect is that text doesn't get shifted back and forth depending on
how the character and <tab> placement is interpreted with respect to the tab
stops.  In otherwords, unless you can see the invisibles, the detabbed and
retabbed lines should appear to be identical to the original.

I'm using MacPerl 5.20r4 ...same thing happens under UNIX Perl v5.004_03.

BTW, BBEdit faithfully detabs and retabs correctly.  :-)

Does anybody out there have a version of Text::Tabs that works correctly?


- Taylor


<----------- CUT HERE ----------->
#!perl -w

use Text::Tabs;
$tabstop = 4; 			# Reserved variable for Text::Tabs (?)


foreach $filename ( @ARGV )
{

	open(IN, "<$filename") || die "Can't open $filename ($!)";
	while( <IN> )
	{
		# From documentation:
		#	@lines_without_tabs = expand(@lines_with_tabs); 
		#	@lines_with_tabs = unexpand(@lines_without_tabs); 

		printf "ORIGINAL: $_";
		$detabbed = expand( $_ );
		printf "DETABBED: $detabbed";
		$retabbed = unexpand( $detabbed );
		printf "RETABBED: $retabbed";
		printf "\n";

		printf "$_";				# Show again w/no leading 
		printf "$detabbed";
		printf "$retabbed";
		printf "\n";

	}
	close(IN) || die "Can't close $filename ($!)";

}
<----------- CUT HERE ----------->
There are 6 <tab>'s between these markers:  ->						<-
There are 3 <tab>'s between HERE and			HERE
There are 6 <tab>'s between these markers:  ->						  <-
		2 <tab>'s started this line; 3 <tab>'s between HERE and			HERE
	  A	   	strange		Line  a	 funny	line       	.

[END OF FILE]
<----------- CUT HERE ----------->
  :
ORIGINAL: There are 6 <tab>'s between these markers:  ->						<-
DETABBED: There are 6 <tab>'s between these markers:  ->                      <-
RETABBED: There are 6 <tab>'s between these markers:	->						<-

There are 6 <tab>'s between these markers:  ->						<-
There are 6 <tab>'s between these markers:  ->                      <-
There are 6 <tab>'s between these markers:	->						<-


ORIGINAL: 		2 <tab>'s started this line; 3 <tab>'s between HERE and			HERE
DETABBED:         2 <tab>'s started this line; 3 <tab>'s between HERE and         HERE
RETABBED: 		2 <tab>'s started this line; 3 <tab>'s between HERE and 		HERE

		2 <tab>'s started this line; 3 <tab>'s between HERE and			HERE
        2 <tab>'s started this line; 3 <tab>'s between HERE and         HERE
		2 <tab>'s started this line; 3 <tab>'s between HERE and 		HERE

ORIGINAL: 	  A	   	strange		Line  a	 funny	line       	.
DETABBED:       A     strange     Line  a  funny  line        .
RETABBED: 	  A 	strange 	Line  a  funny	line		.

	  A	   	strange		Line  a	 funny	line       	.
      A     strange     Line  a  funny  line        .
	  A 	strange 	Line  a  funny	line		.

  :
<----------- CUT HERE ----------->

  +------------------------------------------------------------------+
  |  Taylor Leaming                           phone: (512) 895-6211  |
  |  Imaging Systems Division       pager: (800)SKYTEL2 PIN#1385224  |
  |  Consumer Systems Group     <http://isd.sps.mot.com/~leamingt/>  |
  |  Motorola SPS               <mailto:leamingt@tobor.sps.mot.com>  |
  +------------------------------------------------------------------+

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch