Bug 119223

Summary: perl length() doesn't work right with format writes
Product: Red Hat Enterprise Linux 3 Reporter: erikj
Component: perlAssignee: Jason Vas Dias <jvdias>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 3.0CC: pkesling
Target Milestone: ---   
Target Release: ---   
Hardware: ia64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-11-10 18:47:08 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Red Hat Bugzilla 2004-03-26 17:43:08 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1)
Gecko/20030225

Description of problem:
The perl that comes with AS3 seems to have a problem with handling 
of length() when using write() to write out forms.

The AS21 version of perl does not have this problem.
I also built my own perl 5.8.3 (from source) on an AS3 system, and
the resulting perl did not have this problem.

I wrote a small test case to show the problem.
"testfile" is a large text file with no line feeds. 
For mine, I just took /usr/share/magic and removed all the line feeds
so it was one giant line.

The format defined just prints 256 characters at a time.

Here is the example:
#! /usr/bin/perl

$line = `cat testfile`;

open MAKEFILE, ">testout" or die "Error opening file testout for write\n";

format MAKEFILE =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\~
$line
.


local $: = " \t\n";

print "Length before write: ", length $line, "\n";
write MAKEFILE;
print "Length AFTER write: ", length $line, "\n";

close MAKEFILE;


Output from AS21:

% perl foo.pl
Length before write: 20799
Length AFTER write: 20549

Output from AS3:
% perl foo.pl
Length before write: 20799
Length AFTER write: 20799

Notice that length didn't change.

The example we hit in the real world was a perl script associated
with a weather modeling package.  It depending on length decreasing
in a while loop to "break up long lines".  On AS3, it hangs forever
because length() never decreases.

Version-Release number of selected component (if applicable):
perl-5.8.0-88.4

How reproducible:
Always

Steps to Reproduce:
see above

Additional info:

Comment 1 Red Hat Bugzilla 2004-08-26 16:31:04 UTC
I think this is perl bug 24767

 http://rt.perl.org/rt3/index.html?q=24767

And the work around is to set this env variable before running
perl.  ie

export LANG=en_US

Comment 2 Red Hat Bugzilla 2005-11-10 18:47:08 UTC
Very sorry for the long delay in processing this bug.

I'm not sure what the "problem" is here. 

I don't think this bug has anything to do with perl bug 24767, which is,
BTW, fixed in the current RHEL-3 perl release.

I don't have access to perl 5.6 for testing, so 5.8 behaviour may have
changed - but in 'man perlform' the RHEL-3 perl-5.8.0, it clearly states:

 
       Picture fields that begin with ^ rather than @ are treated specially.
       With a # field, the field is blanked out if the value is undefined.
       For other field types, the caret enables a kind of fill mode.  Instead
       of an arbitrary expression, the value supplied must be a scalar vari-
       able name that contains a text string.  Perl puts as much text as it
       can into the field, and then chops off the front of the string so that
       the next time the variable is referenced, more of the text can be
       printed.  (Yes, this means that the variable itself is altered during
       execution of the write() call, and is not returned.)

So these two programs behave exactly the same under perl-5.8.0 on RHEL-3, and
under perl-5.9.3 (bleadperl) on FC-5 :

--- t1.pl:
#!/usr/bin/perl
$line='12345678';
format STDOUT =
^<<<~~
$line
.
    print "Length before:",length($line),"\n";
    write STDOUT;
    print "Length after:", length($line),"\n";
---
$ ./t1.pl
Length before:8
1234
5678
Length after:0

--- t2.pl:
#!/usr/bin/perl
$line='12345678';
format STDOUT =
@<<<
$line
.
    print "Length before:",length($line),"\n";
    write STDOUT;
    print "Length after:", length($line),"\n";

$ ./t2.pl
Length before:8
1234
Length after:8

Hence I think this is 'NOTABUG' - if you disagree, please re-open citing
perl documentation to the contrary.