Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

trying to identify the exact data stored from dump - [ ' ];

by asham (Novice)
on Jan 11, 2014 at 21:38 UTC ( #1070293=perlquestion: print w/replies, xml ) Need Help??
asham has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am facing following issue:

1) Several tasks are performed and an array reference is returned.

2) We use this array reference to check for existence of elements containing "only white-space characters" and remove those elements.

3) The final array reference should contain valid data or might be empty after 2). For the same final array reference, we take dump using Data::Dumper module and interestingly we are getting following:

$VAR1 = [ ' ];

Also the same array reference was confirmed to be containing 1 element using (scalar @$arrayReference). Could someone please tell me what this corresponds to? what could the data element be expected to be?

As per my understanding, a 'can not be printed by itself. For that we get something like:

$VAR1 = [ '\'' ];

I guess I a missing something trivial here. Please help.

Replies are listed 'Best First'.
Re: trying to identify the exact data stored from dump - [ ' ];
by choroba (Bishop) on Jan 11, 2014 at 21:44 UTC
    Make Data::Dumper display special characters:
    $Data::Dumper::Useqq = 1;

    Seems like a ["\r"] or ["\b"].

    Update: print Dumper ["\b \r"];

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thanks a lot that really helped. It was \b. Got confused because of the dump data shown.

      Hi, Thanks for the help. I was able to resolve \b issue. But now I am running into similar territory again. :(

      1) In one of the data (array reference) being obtained by me, I am getting something like below: (Dumper output for an array reference)

      $VAR1 = [ " \n" ];

      2) the same when printed using Data::Dumper->Dump($arrayReference) gave me following:

      $VAR2 = " \n";

      And scalar (@$arrayReference) returned 2.

      a) Just wondering in what case $VAR1 will not be showing at all? There are two elements and none of the output above, mention about one element at all.

      b) What is the best way to get the Data Dump? Am I missing something? till now I had pretty good vibe about Data::Dumper.

      Note: here $Data::Dumper::Useqq = 1; too

      I am also trying by using $Data::Dumper::Indent=0 to see if that gives me some clue about space or something in Dumper output. But not sure if that will really be helpful for that hidden element.

      My sincere apologies for such trivial questions. and thanks a lot for your time.

        You get $VAR1 = ...; $VAR2 = ...; when you pass a list or an array to Dumper, and $VAR1 = [...] if you pass an array ref.

        Just wondering in what case $VAR1 will not be showing at all?

        There are two options: with Dump the second parameter specifies how the variable is named; so if you pass a second argument, there'll be now $VAR1.

        The other option is to set the $Data::Dumper::Purity variable, as described in the documentation.

        I personally just use print Dumper $somereference; (and yes, Useqq = 1), which gives the least ambiguous output.

        You should have done Data::Dumper->Dump($arrayReference) as you said you did, but you really did Data::Dumper->Dump(@$arrayReference). If you want to dump an array or hash, pass a reference to it.
Re: trying to identify the exact data stored from dump - [ ' ]; (ddumper)
by Anonymous Monk on Jan 11, 2014 at 22:48 UTC
    use Data::Dumper qw/ dd /; dd( $VAR );
      I think you meant Data::Dump and dd is auto-exported. :)

      perl -e' use Data::Dump; $var="\b"; dd $var' "\b"

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1070293]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2018-06-23 21:45 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.