Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

write() removes trailing spaces

by jesuashok (Curate)
on Jun 09, 2006 at 08:06 UTC ( #554441=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on write() removes trailing spaces
Select or Download Code
Re: write() removes trailing spaces
by ioannis (Priest) 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
      Hi ioannis

      Thanks for your reply.

      what will happen if $c is only

      $c = "c ";
      The last spaces are removed. This detail is not documented in any of the perl documents.

      "Keep pouring your ideas"
        if $c is set to 'c ', then it will append 9 spaces at the end, so the string can occupy the 11 posisions. (Remember, it is 1 + 10 .)
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.

      Hi

      Joost, It sounds good. Thanks a lot for you confirmation.

      "Keep pouring your ideas"
Re: write() removes trailing spaces (plagiarized)
by shmem (Canon) 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}

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://554441]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2014-10-22 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (118 votes), past polls