Hi Monks,

Could you please kindly help with printing empty line into report when using Perl v5.32?

Background: while transferring an old Perl application (a collection of scripts) from RHEL7 (Perl 5.16) to RHEL9 (Perl 5.32), found some tests failing in 5.32 because whitespace value refuses to get printed on its own line into report when format uses picture line that starts with caret and ends with two tildes.

Removing tildes (or running the following sample code in Perl 5.16) results in whitespace printed on its own line without issues.

I wrote the following script for the purpose of illustration of the phenomenon. Note: same behavior is displayed when using "format NAME = ..." syntax instead of "$format = ..." + "eval $format".

#!/usr/bin/perl use strict; use warnings; my ($date, $reference, $rep_line); my $format = q/format REP_TOP = @<<<<<<<<<<<<<<< @>>>>>>>>>>>>>> $date, $reference . /; eval $format; $format = q/format REP = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~ $rep_line . /; eval $format; $date = "11/11/2011"; $reference = "REF123"; open my $fh, ">", "/tmp/test.txt" or die "$!\n"; $fh->format_name("REP"); $fh->format_top_name("REP_TOP"); $fh->autoflush(1); $fh->format_lines_per_page(10); for (@ARGV) { $rep_line = $_; write $fh; }
Running this script as follows prints only lines with non-whitespace values:
$ perl testformat.pl 0 1 " " 2 3 " " 4 5; $ cat /tmp/test.txt 11/11/2011 REF123 0 1 2 3 4 5
Expected (and as it works with 5.16):
$ perl testformat.pl 0 1 " " 2 3 " " 4 5; $ cat /tmp/test.txt 11/11/2011 REF123 0 1 2 3 4 5
Assuming I still want to use format, how would you advise to overcome this and achieve printing of whitespace values into separate lines of report? I need to keep ~~ there to be able to wrap longer values. It appears that ~~ is confused by Perl with single ~. Any idea WHY the behavior changed? Is it a bug?

In reply to perl 5.32 format question by hotpelmen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.