[comp.lang.perl] format with tilde

FFAAC09@cc1.kuleuven.ac.be (Paul Bijnens) (02/19/91)

I have a problem using single and double tilde in formats.
I have a file with each line consisting of 20 fields separated by
a tab. Most of the fields are blank, some are short and the rest
is very long (up to 1000 chars or more).
For printing this out, I wanted to use perl (what other program
does not choke on such long lines?).  A little skeleton of the
program (which does also some other things) follows:

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
format =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 $Xword
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~
 $Xvd
    ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
     $Xvd
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~
 $Xhn
    ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
     $Xhn
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~
 $Xdh
    ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
     $Xdh
------------------------------------
.

while (<>) {
    reset 'X';
    chop;
    split(/\t/);
    $Xword = @_[1];
    if (@_[2] =~ /./) { $Xvd = "VD: " . @_[2]; }
    if (@_[3] =~ /./) { $Xhn = "HN: " . @_[3]; }
    if (@_[4] =~ /./) { $Xdh = "DH: " . @_[4]; }
    write;
}
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

The format makes an "undented" (vs. "indented") paragraph of each
field (except the first).  If the field is blank, then is not
printed.  The output I expected would look like:


-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
a cow
VD: bla bla bla bla
DH: blablalbalb blabla
    bla blab lab la lba
    bla bla bla bla bla
------------------------
a horse
VD: blabla blabla bla
    blab lab la blalba
    blablabla balbla bla
    bla bla bal balba
    bla bla blba blabla
    blab lblablabal
-------------------------
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


But it rather looks like:

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
a cow
VD: bla bla bla bla
DH: blablalbalb blabla
    bla blab lab la lba
bla bla bla bla bla
------------------------
a horse
VD: blabla blabla bla
    blab lab la blalba
blablabla balbla bla
    bla bla bal balba
bla bla blba blabla
    blab lblablabal
-------------------------
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

Instead of just repeating the line with two tildes, it
repeats the pair of lines.
What do I do wrong?  Or isn't the format intended to be used
for this purpose?

Btw, in perl.4.0, beta release in lib/look.pl, we find:
    ;#Usage: &look(*FILEHANDLE,$key,$dict,$fold)
and a little bit further:
    local(*FH,$key,$fold,$dict) = @_;
... If in doubt, look at the code...

Polleke   (Paul Bijnens)
Linguistics dept., K. University Leuven, Belgium
FFAAC09@cc1.kuleuven.ac.be

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/21/91)

In article <91049.163743FFAAC09@cc1.kuleuven.ac.be> FFAAC09@cc1.kuleuven.ac.be (Paul Bijnens) writes:
: I have a problem using single and double tilde in formats.
: I have a file with each line consisting of 20 fields separated by
: a tab. Most of the fields are blank, some are short and the rest
: is very long (up to 1000 chars or more).
: For printing this out, I wanted to use perl (what other program
: does not choke on such long lines?).  A little skeleton of the
: program (which does also some other things) follows:
: 
: -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
: format =
: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
:  $Xword
: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~
:  $Xvd
:     ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
:      $Xvd
: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~
:  $Xhn
:     ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
:      $Xhn
: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~
:  $Xdh
:     ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
:      $Xdh
: ------------------------------------
: .
...
: Instead of just repeating the line with two tildes, it
: repeats the pair of lines.
: What do I do wrong?  Or isn't the format intended to be used
: for this purpose?

No, it should work, but it doesn't.  You're the first person who's ever
put a ~~ line directly after a ~ line, apparently.  Anyway, I found the
bug, so it'll be fixed in 4.0.
 
: Btw, in perl.4.0, beta release in lib/look.pl, we find:
:     ;#Usage: &look(*FILEHANDLE,$key,$dict,$fold)
: and a little bit further:
:     local(*FH,$key,$fold,$dict) = @_;
: ... If in doubt, look at the code...

But the code will change to match the documentation in this case, since
the book has it the other way around.

Larry

gorpong@ping.chi.il.us (Gordon C. Galligher) (02/25/91)

This is not really a follow-up to the qwestion posed by Paul Bijnens, but
it does have to do with format's and the tilde.  I was wondering why the
tilde is expanded to a space when the 'write;' call comes in?  The manual
states that the tilde really should be put at the front of the line for
redability, but it screws up your format because it throws an extra space
in the output.  Is it possible to remove this in 4.0, or at least make it
an option which you can disable with a variable or something?  My previously
posted problem with eval and format also used the double-tilde approach and
I was forced to put the ~~ at the end of my eval'd string because it screwed
up things.  I know the addage goes, "if it ain't broke, don't fix it," but
the manual page states that "Normally you should put it in front," and doing
so screws up your picture.  If it is not feasible to add this change to
Perl, then I would remove that phrase from the manual page.  Just a thought.
By the way, any ideas on my original query?  I have not received anything
yet.  Thanks.

		-- Gordon.
-- 
Gordon C. Galligher	9127 Potter Rd. #2E	Des Plaines, IL    60016-4881
gorpong@ping.chi.il.us    gorpong%ping@uu.psi.com   ...!uu.psi.com!ping!gorpong
	"I know how it works....That's why I don't like it"
		-- Chip Salzenberg on SCO "UNIX" C2 Security Package

mitchh@gold.gvg.tek.com (Mitch Hendrickson) (02/26/91)

In article <11526@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
>No, it should work, but it doesn't.  You're the first person who's ever
>put a ~~ line directly after a ~ line, apparently.  Anyway, I found the
>bug, so it'll be fixed in 4.0.

Sheesh, I found this back around pl 20-something, and I just thought I
was being stupid....  Oh well.  Thanx Larry.  Now, if I can just
remember what it was I was trying to do with it... :-)

-Mitch


-- 
Mitch Hendrickson		mitchh@gold.gvg.tek.com
Grass Valley Group, Inc.	(of course I don't speak for them!!)
P.O. Box 1114  (M/S N3-2F)
Grass Valley, CA 95945		"Let there be songs to fill the air..."

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (03/08/91)

In article <1991Feb24.213938.18986@ping.chi.il.us> gorpong@ping.chi.il.us (Gordon C. Galligher) writes:
: This is not really a follow-up to the qwestion posed by Paul Bijnens, but
: it does have to do with format's and the tilde.  I was wondering why the
: tilde is expanded to a space when the 'write;' call comes in?  The manual
: states that the tilde really should be put at the front of the line for
: redability, but it screws up your format because it throws an extra space
: in the output.

The rule about picture lines in formats is that your spacing is inviolate,
so that you can line things up easily.  Deleting ~ would violate this rule.

: Is it possible to remove this in 4.0, or at least make it
: an option which you can disable with a variable or something?  My previously
: posted problem with eval and format also used the double-tilde approach and
: I was forced to put the ~~ at the end of my eval'd string because it screwed
: up things.

If the front of your picture wouldn't be spaces anyway, putting it at the
end is perfectly fine.  The reform program on page 321 does this.

: I know the addage goes, "if it ain't broke, don't fix it," but
: the manual page states that "Normally you should put it in front," and doing
: so screws up your picture.  If it is not feasible to add this change to
: Perl, then I would remove that phrase from the manual page.  Just a thought.

It says "Normally you should put it at the front if possible, for visibility."
This implies that sometimes it's not possible to put it at the front, and
that the reason for putting it at the front is not legalistic, but stylistic.

Larry