http://www.perlmonks.org?node_id=554441

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

Dear fello monks,

There is a strange behaviour with the write() function, that is not documented: a little program would be the best way to explain

#!/usr/bin/perl format STDOUT = @<<<<@<<<<@<<<<<<<<<< $a, $b, $c . $a = "a"; $b = "b"; $c = "c "; write(STDOUT);

I'd expect something like this to be printed:

'a b c '


What I get instead is

'a b c'

In the documentation there's no advice that trailing spaces will be automatically removed, nor a way to avoid that is descripted.

"Keep pouring your ideas"

Considered by shmem: unapprove (plagiarized from p5p)
Approval removed by Arunbear; Keep: 1, Edit: 13, Reap: 11

Replies are listed 'Best First'.
Re: write() removes trailing spaces
by Joost (Canon) on Jun 09, 2006 at 10:22 UTC
    Given that formats are intended to create plain text printable reports, removing trailing spaces certainly makes sense, if only for efficiency.

    But indeed, it might be a good idea to document that somewhere (I havent searched everywhere, but it doesn't appear to be documented right now). If it's really undocumented, you could write a documentation patch and submit it to the perl5 porters.

      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: write() removes trailing spaces
by ioannis (Abbot) on Jun 09, 2006 at 08:35 UTC
    There is nothing strange. The following altered code demonstrates that your $c variable contains 13 chars , which you want displayed within 11 space holders (1+10). Two chars werer choped, as per your request .
    format STDOUT = @<<<<@<<<<@<<<<<<<<<<END $a, $b, $c . $a = "a"; $b = "b"; $c = "c .bc"; print 'len=',length $c; write(STDOUT);

    Produces this output:

    len=13 a b c .END
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: write() removes trailing spaces (plagiarized)
by shmem (Chancellor) on Oct 09, 2006 at 09:28 UTC
    Ripped from p5p.

    Original post is here.

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