FAQ
# New Ticket Created by AInaganti@bankofny.com
# Please include the string: [perl #27349]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=27349 >


Hi,
We are having a problem with printing reports using perl format. Each
line on our report has to be 133 bytes where 133rd byte is a newline
character.
So we are padding the strings with white spaces. However on the report
the string is getting truncated ( all the white spaces towards the end
are getting truncated. Here is a sample script:
#!/usr/bin/perl

my $fileName ="/tmp/anita/tempreport.rpt";
my $reportTitle = " " x 49 . "AAA UNMATCHED TRADE STATUS REPORT" . " " x
50;
my $test = "Hello";
my $strlen = length($test);
my $newString = $test . " " x (132-$strlen)."\n";
#my $newString = sprintf("%-132s",$test);
my $slen = length($newString);
print "length = $slen \n";

open(OUTFILE, ">$fileName") or die "Can't open $fileName file\n";

write(OUTFILE);

format OUTFILE_TOP =
1+_________________________________________________________________________________________________________________________________+

@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$reportTitle
PAGE: @##########
$%

+_________________________________________________________________________________________________________________________________+
.

format OUTFILE =

^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$newString
.
exit 0

This is the output:
$ reportpadding.pl
length = 133

Here is the report:
1+_________________________________________________________________________________________________________________________________+
AAA UNMATCHED TRADE
STATUS REPORT
PAGE: 1

+_________________________________________________________________________________________________________________________________+
Hello

This is the version we are using:
This is perl, v5.6.1 built for aix-thread-multi
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 631 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 12:48:19 Mar 13 2002

Is this a known bug? If so was it fixed. Please let us know.

Thanks
Anita Inaganti



________________________________________________________________________
The information in this e-mail, and any attachment therein, is confidential and for use by the addressee only. If you are not the intended recipient, please return the e-mail to the sender and delete it from your computer. Although The Bank of New York attempts to sweep e-mail and attachments for viruses, it does not guarantee that either are virus-free and accepts no liability for any damage sustained as a result of viruses.

Search Discussions

  • H.Merijn Brand at Mar 4, 2004 at 10:39 am

    On Wed 03 Mar 2004 15:50, "AInaganti@bankofny.com (via RT)" wrote:
    # New Ticket Created by AInaganti@bankofny.com
    # Please include the string: [perl #27349]
    # in the subject line of all future correspondence about this issue.
    # <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=27349 >


    Hi,
    We are having a problem with printing reports using perl format. Each
    line on our report has to be 133 bytes where 133rd byte is a newline
    character.
    So we are padding the strings with white spaces. However on the report
    the string is getting truncated ( all the white spaces towards the end
    are getting truncated. Here is a sample script:
    This is the way formats are to behave, especially when using ^<<<<

    This is no bug, but there is a workaround:

    a5:/tmp 104 > cat xx.pl
    #!/pro/bin/perl

    use strict;
    use warnings;

    format STDOUT =
    @<<<<<<<<<<<<<<<<<<<
    $_
    .

    $_ = "abcdef";
    write;
    a5:/tmp 105 > perl xx.pl | cat -ve
    abcdef$
    a5:/tmp 106 >


    And now make the lines longer:

    a5:/tmp 110 > cat xx.pl
    #!/pro/bin/perl

    use strict;
    use warnings;

    unless (open STDOUT, "|-") {
    while (<>) {
    s/$/" " x (20 - length)/e;
    print;
    }
    exit;
    }

    format STDOUT =
    @<<<<<<<<<<<<<<<<<<<
    $_
    .

    $_ = "abcdef";
    write;

    close STDOUT;
    a5:/tmp 111 > perl xx.pl | cat -ve
    abcdef $
    a5:/tmp 112 >



    --
    H.Merijn Brand Amsterdam Perl Mongers (http://amsterdam.pm.org/)
    using perl-5.6.1, 5.8.0, & 5.9.x, and 806 on HP-UX 10.20 & 11.00, 11i,
    AIX 4.3, SuSE 8.2, and Win2k. http://www.cmve.net/~merijn/
    http://archives.develooper.com/daily-build@perl.org/ perl-qa@perl.org
    send smoke reports to: smokers-reports@perl.org, QA: http://qa.perl.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedMar 4, '04 at 1:13a
activeMar 4, '04 at 10:39a
posts2
users2
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase