write while( length $name );

Discussion in 'Perl' started by Harry DeLano, May 3, 2004.

  1. Harry DeLano

    Harry DeLano Guest

    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
     
    Harry DeLano, May 3, 2004
    #1
    1. Advertising

  2. Harry DeLano

    Joe Smith Guest

    Harry DeLano wrote:

    > 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
     
    Joe Smith, May 4, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mitchua
    Replies:
    5
    Views:
    2,828
    Eric J. Roode
    Jul 17, 2003
  2. =?Utf-8?B?SG96aQ==?=
    Replies:
    1
    Views:
    7,024
    Ken Cox [Microsoft MVP]
    Jun 2, 2004
  3. Replies:
    2
    Views:
    5,970
  4. ctk70
    Replies:
    2
    Views:
    524
    ctk70
    Feb 10, 2005
  5. Replies:
    0
    Views:
    495
Loading...

Share This Page