write while( length $name );

H

Harry DeLano

I found this code in /usr/bin/dprofpp. I am getting garbled output from
dprofpp so I thought I'd try to debug it. The code in the subject
line has me baffled. Some dprofpp code excerpts:

...
$~ = 'STAT';
...
format STAT =
^>>> ^>>>> ^>>>>> ^>>>>> ^>>>>> ^>>>>>
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$pcnt, $secs, $csecs, $ncalls, $percall, $cpercall, $name
 
J

Joe Smith

Harry said:
I found this code in /usr/bin/dprofpp. I am getting garbled output from
dprofpp so I thought I'd try to debug it. The code in the subject line
has me baffled. Some dprofpp code excerpts:

...
$~ = 'STAT';
...
format STAT =
^>>> ^>>>> ^>>>>> ^>>>>> ^>>>>> ^>>>>>
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$pcnt, $secs, $csecs, $ncalls, $percall, $cpercall, $name
.

So how does this code not loop forever?

The answer is in "perldoc perlform".

Perl puts as much text as it
can into the field, and then chops off the front of the string so that
the next time the variable is referenced, more of the text can be
printed. (Yes, this means that the variable itself is altered during
execution of the write() call, and is not returned.)

You might be interested in the message I posted to comp.lang.perl.misc
4/18/2004 1:33am (Message-ID: nntp:f3rgc.8641$hw5.7761@attbi_s53).

unix> cat temp
my $FO_UN = " @<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<<<<<<<<<";

$name = 'John Doe';
$note = '123456789 abcdefghi ABCDEFGHI jklmnopqr JKLMNOPQR stu';
$psec .= swrite(<<"END", $name, $note);
$FO_UN
END

print qq/$psec\n/;
#---------------------------------------------------------------------------
sub swrite {
my($format,$arg1,$arg2) = @_;
$^A = "";
print "before: arg2='$arg2'\n";
formline($format, $arg1, $arg2);
print "after: arg2='$arg2'\n";
substr($format,1,14) = ' ' x 14; # Done with "@<<<<<<<<<<<<<" part
formline($format, $arg2) while $arg2 ne ""; # Do multi-line
return $^A;
}
unix> perl temp
before: arg2='123456789 abcdefghi ABCDEFGHI jklmnopqr JKLMNOPQR stu'
after: arg2='ABCDEFGHI jklmnopqr JKLMNOPQR stu'
John Doe | 123456789 abcdefghi
| ABCDEFGHI jklmnopqr
| JKLMNOPQR stu

unix>

-Joe

P.S. Please post to comp.lang.perl.misc next time, not comp.lang.perl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top