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

Re: [MacPerl] Curious behaviour in Text::Tabs



My bad.

I should have known better...and it didn't occur to me until this morning
when I was playing with expand/unexpand on UNIX...

The test case lines were being processed by the Perl Text::Tabs module where
the module (correctly) assumed that the start of each string that was passed
was the start of a line.  Given that, the tabstops were assumed to be set at
4,8,12... from the start of the line, which is correct.

THEN, being the bonehead that I am, I went off and prepended some text to
the start of each line that contained 10 characters:

    "ORIGINAL: "
    "DETABBED: "
    "RETABBED: "

So of course that would throw off the tabbing when examined later...by two
characters.  Had I chosen to prepend some text that happened to be in
multiples of 4 characters in length, I wouldn't have seen the seemingly
odd behaviour.  In short, I caused the anomalous behaviour.  Duh!

(stupid...stupied...stupid!...)


My apologies for wasting bandwidth on such a lame question!


What was that thing about affecting that which you are trying to measure...?

- Taylor


At 11:50 AM -0600 5/22/98, Taylor Leaming wrote:
> 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

  +------------------------------------------------------------------+
  |  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