Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

perl null padding

by m.y (Novice)
on Apr 11, 2008 at 23:09 UTC ( [id://679883]=perlquestion: print w/replies, xml ) Need Help??

m.y has asked for the wisdom of the Perl Monks concerning the following question:

How can I null pad a string without using pack? I need to null pad a string so that its 24 characters. I have this currently:
my $str = "abcde"; $str .= "\0" x (24 - length($str));
The problem is when I do this in a mod_perl environment it never reaches the line after the null padding. Is this not the way to do it?

Replies are listed 'Best First'.
Re: perl null padding
by mr_mischief (Monsignor) on Apr 11, 2008 at 23:30 UTC
    When I do this, I get s length of 24 for $atr:
    $str = 'abcde'; $str .= "\0" x (24 - length $str); print length $str; print "\n";
    How are you using the string? Printing something with null bytes might not do what you expect and probably won't do what you want.
      I get the right length also in a non mod_perl environment. For some reason in mod_perl it never goes past the null padding line.
        For some reason in mod_perl it never goes past the null padding line.

        What direct observation are you making that lead you to conclude that?

        If you comment out the padding line does it correctly print the length of the unpadded string?

        Have you put a die() or similar after the padding to see if execution is really reaching that point?

        It seems much more likely that something you are doing later in the script with the null bytes is causing a mode of failure that prevents the data that's been written to response from appearing on the client.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found