Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: perl 5.32 format question

by kcott (Archbishop)
on May 29, 2023 at 13:17 UTC ( [id://11152465]=note: print w/replies, xml ) Need Help??


in reply to perl 5.32 format question

G'day hotpelmen,

The oldest version I have is v5.30.0, so I couldn't attempt to replicate your results. I had a look in perlform for a number of versions but couldn't find any change. My look was brief; you may want to study more closely:

I suspect you may be right about '~' & '~~'. There does seem to be some conflict between "perlform: Suppressing Lines Where All Fields Are Void" and "perlform: Repeating Format Lines".

"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?"

This code, pm_11152452_testformat.pl, worked for me.

#!/usr/bin/env perl use strict; use warnings; use autodie; use constant REP_LINE_MAX_LENGTH => 3; # For demo only print "Perl version: $^V\n"; my $outfile = '/tmp/pm_11152452_test.txt'; my ($date, $reference, $rep_line); format REP_TOP = @<<<<<<<<<<<<<<< @>>>>>>>>>>>>>> $date, $reference . format REP = ^*~~ $rep_line . $date = '11/11/2011'; $reference = 'REF123'; open my $fh, '>', $outfile; $fh->format_name('REP'); $fh->format_top_name('REP_TOP'); $fh->autoflush(1); $fh->format_lines_per_page(10); for (@ARGV) { $rep_line = substr($_, 0, REP_LINE_MAX_LENGTH); write $fh; } # For demo only system cat => $outfile; unlink $outfile;

I kept REP_LINE_MAX_LENGTH very short for demo purposes; you'll want it to be 33 (if I counted correctly). I tested it on three versions:

$ ./pm_11152452_testformat.pl zero one " " two three " " four five Perl version: v5.30.0 11/11/2011 REF123 zer one two thr fou fiv $ ./pm_11152452_testformat.pl zero one " " two three " " four five Perl version: v5.32.0 11/11/2011 REF123 zer one two thr fou fiv $ ./pm_11152452_testformat.pl zero one " " two three " " four five Perl version: v5.36.0 11/11/2011 REF123 zer one two thr fou fiv

See how you go with 5.16.

— Ken

Replies are listed 'Best First'.
Re^2: perl 5.32 format question
by hotpelmen (Scribe) on May 30, 2023 at 16:23 UTC
    Thank you kcott, your help is much appreciated! I guess ^*~~ would be practical if one wants to do their own wrapping (or trimming, like you did) of the printed values. It's interesting that in the format you suggested, tildes do not have the same effect on code's ability to create blank lines. One can wonder if it's intentional or an omission.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found