From: Stephen Riehm <[email-masked]>
Date: 26 Mar 93 09:53:32 GMT
Newsgroups: comp.lang.perl

Stephen Riehm <[email-masked]> writes:

>Hi guys 'n' gals,
>	I am trying to wrap lines longer than the screen width, word
>	breaks don't interest me, but tabs do!
etc etc etc...

Thanks to the millions of people who replied, the number and range of
replies was simply overwhelming!

To sum up what I have found to be the most elegant solutions I
received the following:
---
# From: [email-masked]
# detab: convert tabs to spaces
sub detab       # (tabbed,tabsize) -> untabbed
        { local($line,$tabsize)=@_;
          local($_,$chunk);

          defined($tabsize) || ($tabsize=8);

          # Bug in regexps?
          # s/\t/' ' x ($tabsize-(length($`)%$tabsize))/eg;

          $_='';
          for $chunk (split(/\t/,$line))
                { $_.=$chunk;
                  $_.=(' ' x ($tabsize-(length($_) % $tabsize)));
                }

          s/[ \t]+$//;

          return $_;
        }
---

Once I got this, it was pretty simple to put together the
following while loop:

---
    while( <> )
	{
	chop;
	# convert tabs to spaces
	# If the line is empty, turn it into a single space so that it
	# gets printed by the while loop below
	$_ = &detab( $_, $tabsize ) || " ";
	while( s/(.{1,$width})// && ( ++$line_num < $max_lines ) )
	    {
	    print "$1\n";
	    }
	last	if $line_num >= $max_lines;
	}
---

And then, just as I had put my script in /usr/local/bin, I got the
following from Eric Arnold:

---
    I just got a response to my question to the newsgroup about "s///eg ...".
    It looks like the most concise version is:

    while ( $test =~ s/\t/" " x (8 - length($`) % 8)/e ){};

    I wanted to use the "g" option to "s/", but it doesn't work like I
    thought.  You have to supply the while loop.
---

So my problem is solved, and thanks to the people who replied, you are
too many to mention, but I am grateful to you all!

Thanks guys 'n' gals!

--------------------------------------------------------------------
Stephen Riehm		   Configuration Management	      _-_|\ 
[email-masked]  Philips Kommunikations Industrie  /     \
Work: +49 911 526 2975	   Nu"rnberg, Germany		     \_.-.!/
Fax:  +49 911 526 3678	   "I was there, now I am here!"          v 
"My company speaks another language, I CAN'T speak on its behalf"
PS: You may think I am joking, I can't speak the language that well so
		PLEASE DON'T REPLY IN GERMAN!
			 - thanks -