Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Perl format line breaking, $FORMAT_LINE_BREAK_CHARACTERS apparently ignored

by trantorvega (Initiate)
on Sep 13, 2012 at 13:34 UTC ( #993491=perlquestion: print w/ replies, xml ) Need Help??
trantorvega has asked for the wisdom of the Perl Monks concerning the following question:

Hello to everyone. In the last hour I've been trying to format the contents of a file using Perl formats, with no success. A brief example:

I example

my $text = "line 1\0line 2\0line 3"; IO::Handle->format_line_break_characters("\0"); format STDOUT = Text: ^* $text ~~ ^* $text . write;
Output:
Text: line 1line 2line 3

II example

my $text = "line 1\nline 2\nline 3"; IO::Handle->format_line_break_characters("\0"); format STDOUT = Text: ^* $text ~~ ^* $text . write;
Output:
Text: line 1 line 2 line 3

III example

my $text = "line 1\nline 2\nline 3"; ####IO::Handle->format_line_break_characters("\0"); format STDOUT = Text: ^* $text ~~ ^* $text . write;
Output:
Text: line 1 line 2 line 3

Taken straight from the perlform man page "The Field ^* for Variable-Width One-line-at-a-time Text" paragraph.

According to the "Using Fill Mode" paragraph, unless I've misunderstood the context, changing the $FORMAT_LINE_BREAK_CHARACTERS or $: variable should change the characters used for line-breaking.

In the first two examples above the variable is correctly set to "\0", instead of its default value " \n-", but that doesn't appear to make lines in the output break on anything other than "\n".

Any ideas? Any obvious misunderstandings on my part?

Comment on Perl format line breaking, $FORMAT_LINE_BREAK_CHARACTERS apparently ignored
Select or Download Code
Re: Perl format line breaking, $FORMAT_LINE_BREAK_CHARACTERS apparently ignored
by NetWallah (Abbot) on Sep 13, 2012 at 22:21 UTC
    I reproduced your issue, and cannot seem to use "$:.

    Sounds like a bug.

                 I hope life isn't a big joke, because I don't get it.
                       -SNL

Re: Perl format line breaking, $FORMAT_LINE_BREAK_CHARACTERS apparently ignored
by Anonymous Monk on Sep 14, 2012 at 01:17 UTC

    IO::Handle->format_line_break_characters("\0");

    Maybe you want STDOUT->format_line_break_characters("\0");

      Apparently it's not a per-filehandle parameter, so that won't work.

        Apparently it's not a per-filehandle parameter, so that won't work.

        Not that its important given this feature never worked :), but

        $ perl - IO::Handle->format_line_break_characters("\0"); ^Z Can't locate object method "format_line_break_characters" via package +"IO::Handle" at - line 1.

        Using STDOUT->format_line_break_characters loads IO::Handle , but then format_line_break_characters dies -- it should have warned (so its not per handle, big deal)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-12-17 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (40 votes), past polls