Usage Profile [Perl] Data :: Dumper module

Thanks to Perl references, so that we can be flexible nested data structures between different data structures.
For example, Hash's value can be scalar, it can also be nested list, they can even continue to be nested hash.

This allows us to write code that does a lot of convenience, but sometimes we wish for these complex data structures
have an intuitive feeling, that it can use perl syntax data structures, and the actual value represented. This is especially in the development phase
helpful!

Just Perl module Data :: Dumper can help us with the job.

Data :: Dumper has object-oriented methods and call directly using two functions,

introduce direct way to use the function, easy to use, should be able to meet the needs of the vast majority here:

Dumper to receive a list of parameters for a scalar or a list of references .
A $ = My "Good";
My B $ = "Bad";
My @my_array = ( "Hello", "World", "123", 4.5 of 5);
My some_hash% = ( "foo", 35, "bar" , 12.4, 2.5, "Hello",
          "Wilma", 1.72e30, "Betty", "BYE \ n-");

## using the function
Print Dumper (A $);
Print Dumper (\ @ my_array);
Print Dumper (\ % some_hash);



roger@roger-desktop:~/sandbox$ perl dump.pl
$VAR1 = 'good';
$VAR1 = [
          'hello',
          'world',
          '123',
          '4.5'
        ];
$VAR1 = {
          'betty' => 'bye
',
          'bar' => '12.4',
          'wilma' => '1.72e+30',
          'foo' => 35,
          '2.5' => 'hello'
        };
$VAR1 = {
          'betty' => 'bye
',
          'bar' => '12.4',
          'wilma' => '1.72e+30',
          'foo' => 35,
          '2.5' => 'hello'
        };
$VAR2 = [
          'hello',
          'world',
          '123',
          '4.5'
        ];
output program named automatically VAR [n] in accordance with the reference position in the list.

 

 

    # if debug flag open, dump key parameters from Launcher
    if ( $debug ) {

        use Data::Dumper;

        $Data::Dumper::Sortkeys = 1; #Sort the keys in the output
        $Data::Dumper::Deepcopy = 1; #Enable deep copies of structures
        $Data::Dumper::Indent = 2;   #Output in a reasonable style (but no array indexes)

        $vmstaf->WriteTestLog( "DEBUG", "VMOTION : " .
            "Dumper Key Parameters from Launcher." );

        $vmstaf->WriteTestLog( "DEBUG", "VMOTION : " .
            "Dumper :: HASH :: generalInfo" );
        print Dumper(\%generalInfo);

        $vmstaf->WriteTestLog( "DEBUG", "VMOTION : " .
            "Dumper :: HASH :: vcInfo" );
        print Dumper(\%vcInfo);

        $vmstaf->WriteTestLog( "DEBUG", "VMOTION : " .
            "Dumper :: HASH :: vmNameToEsx" );
        print Dumper(\%vmNameToEsx);

        $vmstaf->WriteTestLog( "DEBUG", "VMOTION : " .
            "Dumper :: HASH :: esxToSwitches" );
        print Dumper(\%esxToSwitches);

        $vmstaf->WriteTestLog( "DEBUG", "VMOTION : " .
            "Dumper :: HASH :: esxToDevs" );
        print Dumper(\%esxToDevs);

    }

Reproduced in: https: //www.cnblogs.com/licheng/archive/2009/11/27/1612239.html

Guess you like

Origin blog.csdn.net/weixin_34248258/article/details/92633696