Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using perl formats along with write to prepare receipts being sent to a pin printer. When using write into a filehandle - is their any way to intercept and perform a chop? (other than modifying the file after it is written) I want to remove the trailing '\n' (for the entire format) created upon evaluation.

Replies are listed 'Best First'.
Re: perlform and write
by moritz (Cardinal) on Oct 18, 2007 at 18:40 UTC
Re: perlform and write
by shmem (Chancellor) on Oct 19, 2007 at 07:04 UTC
    See Re^3: formats output \r\n question

    --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}
      Thanks - the open sub method works like a charm :)

      Indeed works like a charm, but be careful!

      • Does not work with tied filehandles
      • Does a fork, so if you have open database connections or other external links, be extra careful.

      Enjoy, Have FUN! H.Merijn
        Indeed :) some pointers for anyone finding this with search...

        while( <STDIN> ) blocks, (while can't assume the format is done printing, even if we know the exact # of lines being written) ... solved by exiting the while on N written lines since I know N.

        this is being run from a daemon... which is a child process all too itself. the daemon runs this capture on X formats every K seconds... each pipe is a new child process... defuncts like WOAH! :) remember to reap children Re: Unix Review column