in reply to Re: When can the character length of a Perl Scalar become an issue?
in thread When can the character length of a Perl Scalar become an issue?

I'm not sure what this tells me? It all ran fine. As I said sometimes it trucates sometimes not.
Enter h or 'h h' for help, or 'man perldebug' for more help. main::(./y.pl:6): my $derp = 'x' x 30000; DB<1> n main::(./y.pl:7): my $dom = Mojo::DOM->new('<?xml version="1.0"? +><herp><derp>Test</derp> main::(./y.pl:8): +</herp>'); DB<1> main::(./y.pl:9): say length ( $dom->at( 'derp' )->text ); DB<1> 4 main::(./y.pl:10): $dom->at( 'derp' )->content( $derp ); DB<1> main::(./y.pl:11): say length ( $dom->at( 'derp' )->text ); DB<1> 30000 main::(./y.pl:12): say $dom; DB<1> <?xml version="1.0"?><herp><derp>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (30,000 printed total)</derp> +</herp> Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<1>
  • Comment on Re^2: When can the character length of a Perl Scalar become an issue?
  • Download Code

Replies are listed 'Best First'.
Re^3: When can the character length of a Perl Scalar become an issue?
by marto (Cardinal) on Sep 20, 2023 at 15:58 UTC

    Purely an SSCCE to illustrate adding 30K characters to an XML node. You're likely doing something in the code you're not showing us that causes the problem.

      OK so first I build the scalar- the code just appends values to a long string. It can reach 40,000 or more characters, saved in scalar $E. $E has NO EOL characters. The $E gen code is hard to sanitize. Then $E is appended to a very short file:

      open A, ">>$a"; print A "$E\n"; close A;

        Since files are involved, and *appending* to files, is there a chance that more than one copy of your script runs at the same time, appending to the same file?

        It's better to mark a post as updated. Again without seeing a repeatable example (see previous links) that demonstrates the problem it's difficult to help.

        #!/usr/bin/perl use strict; use warnings; my $derp = 'X' x 40000; open (my $fh, '>', 'derp.txt') or die "can't open derp.txt: $!"; print $fh $derp; close($fh);
        ls -al derp.txt -rw------- 1 marto marto 40000 Sep 21 09:37 derp.txt

        See also open, three arg open, migrating to modern perl.

        Tough to tell without seeing the gen code...

        Best guess is some sort of ctrl char (or seq of chars that get resolved to one). If you make it gen the same line twice, does it break in the same place ?

        Cheers
        Chris