in reply to formats output \r\n question

Set the special variable $\ to "\r\n". See The parable of the falling droplet.

--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}

Replies are listed 'Best First'.
Re^2: formats output \r\n question
by egunnar (Sexton) on Jun 27, 2006 at 15:47 UTC
    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; }
      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}

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

      -derby