hotpelmen has asked for the wisdom of the Perl Monks concerning the following question:
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".
Running this script as follows prints only lines with non-whitespace values:#!/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; }
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?$ perl testformat.pl 0 1 " " 2 3 " " 4 5; $ cat /tmp/test.txt 11/11/2011 REF123 0 1 2 3 4 5
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl 5.32 format question
by haukex (Archbishop) on May 29, 2023 at 12:15 UTC | |
by hotpelmen (Scribe) on May 30, 2023 at 15:59 UTC | |
|
Re: perl 5.32 format question
by kcott (Archbishop) on May 29, 2023 at 13:17 UTC | |
by hotpelmen (Scribe) on May 30, 2023 at 16:23 UTC |