Easy way to print Perl array? (with a little formatting)

后端 未结 11 727
猫巷女王i
猫巷女王i 2021-01-30 10:13

Is there an easy way to print out a Perl array with commas in between each element?

Writing a for loop to do it is pretty easy but not quite elegant....

11条回答
  •  旧时难觅i
    2021-01-30 10:45

    For inspection/debugging check the Data::Printer module. It is meant to do one thing and one thing only:

    display Perl variables and objects on screen, properly formatted (to be inspected by a human)

    Example usage:

    use Data::Printer;  
    p @array;  # no need to pass references
    

    The code above might output something like this (with colors!):

       [
           [0] "a",
           [1] "b",
           [2] undef,
           [3] "c",
       ]
    

提交回复
热议问题