PrePAN

Sign in to PrePAN

Data::Ref Show access path items in deeply nested data structures

Author
jkstill@github
Date
URL
https://github.com/jkstill/Data-Ref
Status
In Review
Good

Synopsis

use Data::Ref;

 my %tc = (

 'HL01-01' => {
     'HL02-01' => [
	 'element 0',
	 'element 1',
	 'element 2'
      ]
 },

 'HL01-02' => {
     'HL02-01' => {
	 K4 => 'this is key 4',
	 K5 => 'this is key 5',
	 K6 => 'this is key 6'
     }
      }

  );

 my $dr = Data::Ref->new (
   {
  DEBUG   => 0,
  DATA	  => \%tc
   }
 );

 $dr->walk;

Description

Data::Ref is used to show the complete path to all elements in a complex data structure consisting of Hash and/or Arrays.

Recently I have spent a fair bit of time manipulating some deeply nested JSON structures that have been read in via some JSON package. At times it has been difficult to determine the exact data path to any particular piece of data..

In addition to being deeply nested, the data is sometimes large, and there may be many elements in each object. The net result is this; it is quite difficult at times to determine the path to any particular element, as it is usually necessary to scroll through several screens of data.

I developed Data::Ref so that I can easily see how to reference any element appearing in the data.

The included demo scripts simply do one of the following: - read in a perl script that contains only data from an object, process with eval and then walk and display the paths to each element - much the same as previous, but read data from a JSON file

See test-files/tc03.pl for the test data.

Note: the standard Markdown code blocks are not behaving in the manner I would normally expect. I will add a short demo when I learn how to do it properly.

In the meantime, please see Data::Ref README.md which contains demos.

Comments

Please sign up to post a review.