Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
PerlMonks  

the repetition operator does not repeat "\x00" Why?

by borisz (Canon)
on Oct 10, 2006 at 10:51 UTC ( #577366=perlquestion: print w/ replies, xml ) Need Help??
borisz has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I wonder, why I can not repeat a binary zero. Can somebody explain this?
use Data::Dumper; $_ = "\x00" x 26; print Dumper($_); $_ = "\x30" x 26; print Dumper($_); __OUTPUT__ $VAR1 = ""; $VAR1 = "00000000000000000000000000";

Comment on the repetition operator does not repeat "\x00" Why?
Download Code
Re: the repetition operator does not repeat "\x00" Why?
by Hofmator (Curate) on Oct 10, 2006 at 11:02 UTC
    The repetition operator works fine, try print length $_; it's Data::Dumper that does not output the '\x00' ...

    -- Hofmator

    Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Data::Dumper prints it for me (Perl 5.8.8, Solaris):
      perl -MData::Dumper -e '$_ = "\x00" x 4; print Dumper $_' | cat -v $VAR1 = '^@^@^@^@';
        You are correct, Data::Dumper prints the '\0' but it is only visible in the output via something like cat -v. Nice trick btw, I didn't know about that. Thank you!

        -- Hofmator

        Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: the repetition operator does not repeat "\x00" Why?
by tinita (Parson) on Oct 10, 2006 at 13:09 UTC
    try
    $Data::Dumper::Useqq = 1;
Re: the repetition operator does not repeat "\x00" Why?
by brian_d_foy (Abbot) on Oct 10, 2006 at 21:13 UTC

    When you really want to see the data, try Devel::Peek:

    use Devel::Peek qw(Dump); $_ = "\x00" x 26; print Dump($_); $_ = "\x30" x 26; print Dump($_); __END__ SV = PV(0x1800884) at 0x1800514 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x3015e0 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +\0 CUR = 26 LEN = 27 SV = PV(0x1800884) at 0x1800514 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x3015e0 "00000000000000000000000000"\0 CUR = 26 LEN = 27
    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review
Re: the repetition operator does not repeat "\x00" Why?
by GrandFather (Cardinal) on Oct 11, 2006 at 03:41 UTC

    or using Data::Dump::Streamer:

    use strict; use warnings; use Data::Dump::Streamer; $_ = "\x00" x 26; Dump($_); $_ = "\x30" x 26; Dump($_);

    Prints:

    $VAR1 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; $VAR1 = '00000000000000000000000000';

    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://577366]
Approved by Hofmator
Front-paged by brian_d_foy
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-04-17 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (439 votes), past polls