Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!orca!fantasy!rkrebs From: rkrebs@fantasy.dsd.es.com (Randall Krebs) Newsgroups: comp.lang.perl Subject: wrapping of "options" in formatted output Message-ID: <1991Jun20.180323.20507@dsd.es.com> Date: 20 Jun 91 18:03:23 GMT Sender: usenet@dsd.es.com Reply-To: rkrebs@fantasy.dsd.es.com (Randall Krebs) Organization: Evans & Sutherland Computer Corp., Salt Lake City, UT Lines: 74 Nntp-Posting-Host: 130.187.85.135 While attempting to construct a white-space line folder (like "fold" except breaks occur on white space), I turned up the following unexpected behavior: format STDOUT = ~~^<<<<<<<<<<<< $cmd . $cmd = "fee -fi -fo -fug -i -smell -the -blood -of -a -perl-bug"; write; produces: fee -fi -fo - fug -i -smell the -blood - of -a -perl- bug My objection is in the treatment of dashes which are preceded by white space. Especially, the one preceding "the" in the command. system: Mips R3000 RISC/os 4.50 Perl 4.010 BTW: here is the white-space line folder so far. I would have shar-chived it, but I don't have a decent shar-chiver. Anybody want to direct me to a copy of a perl shar-chiver? #!/usr/local/bin/perl # # wfold: utility to fold on white space. # # usage: wfold [ -l max_length ] [ file ] ... # # example: wfold -l60 foo # to keep fold lines in file foo which are longer than 60 characters. $linemax = 78; while ($ARGV[0] =~ /^-/) { $_ = shift; if (/^-l(.*)/) { $linemax = ($1 ? 0 + $1 : 0 + shift); } else { die "usage: $0 [ -l max_length ] [ file ] ... \n"; } } $linemin = int($linemax / 2); $pgm = <<"ENDOFOO" while (<>) { 1 while s/\t/' ' x -((length(\$`) % 8) - 8)/e; s/\n?.{$linemin,$linemax} /\$&\n/g if length(\$_) > $linemax; print; } ENDOFOO ; eval $pgm; -- Randall S. Krebs | No offense is made where none is taken. (rkrebs@dsd.es.com) | Evans & Sutherland | - Old Japanese Proverb Salt Lake City, Utah |