in reply to Re: formats output \r\n question
in thread formats output \r\n question

I tried this and it didn't seem to work. I also tried comenting the binmode line out as well. thanks
#!/usr/bin/perl -w use strict; my $name = 'name'; my $home = "town\r\n"; { local $\= "\r\n"; binmode STDOUT; format STDOUT = @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<< \r\n $name, $home . write STDOUT; }

Replies are listed 'Best First'.
Re^3: formats output \r\n question
by shmem (Chancellor) on Jun 27, 2006 at 16:07 UTC
    Darn. Well, TIMTOWTDI.

    You could do:

    #!/usr/bin/perl -w use strict; my $name = 'name'; my $home = "town"; my $form = "\@<<<<<<<<<<<<<<<<<< \@<<<<<<<<<<<<<<<\r\n"; formline($form, $name, $home); print $^A;
    See perlvar, formline for fiddling with the formats. But maybe it would be just easier to postprocess?
    #!/usr/bin/perl -w use strict; my $name = 'name'; my $home = 'town'; printknecht(); # let's fork us a scribe write; format STDOUT = @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<< $name, $home . sub printknecht { return if my $pid = open(STDOUT, "|-"); # return if parent. die "cannot fork: $!" unless defined $pid; while (<STDIN>) { chop; print $_."\r\n"; } exit; }
    See Playing with STDIN and STDOUT for some prosa around this technique.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^3: formats output \r\n question
by derby (Abbot) on Jun 27, 2006 at 15:52 UTC

    $\ is the output record seperator for just the print operator (and not formats). You're probably better off using sprintf instead of formats.

    -derby