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

Re: Avoid warnings while formatting with repeated format lines

by Anonymous Monk
on Aug 24, 2022 at 15:03 UTC ( [id://11146372]=note: print w/replies, xml ) Need Help??


in reply to Avoid warnings while formatting with repeated format lines

I also am not a serious user of format, and it may be that it does not get as much love lately as it should. Since the format does what you want, another way to handle the problem is just to suppress the warning:

use strict;
use warnings;
use open ':locale';

sub print_data
{
my ($name, @f);

  do {
    no warnings 'syntax';
    format START =
.===================.
|@<<<<<<|           |
$name
|       |           |
.=======.===========.
|@<<<<<<|  @<</@>>  |~~
splice( @f, 0, 3 )
.=======.===========.
.
  };
  binmode STDOUT, ':raw:crlf';
  my $ofh = select(STDOUT);
  $~ = "START";
  $name = 'TAB';
  @f = ('Step2', 0, 4, 'Step3', 4,   4);
  write;
}

print_data;

produces

.===================.
|TAB    |           |
|       |           |
.=======.===========.
|Step2  |  0  /  4  |
|Step3  |  4  /  4  |
.=======.===========.

without any warnings. The no warnings ... and format ... were enclosed in a do { ... } simply to limit the scope of the no warnings .... An explicit use warnings 'syntax' after the format would have done the same.

Log In?
Username:
Password:

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

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

    No recent polls found