Thank you for your time and effort with your reply

I really appreciate it.

Below is just your code with some comments/questions etc.

Would appreciate your comments at some stage.

I am really still learning Perl.

use warnings; use strict; use JSON; use Data::Dumper; my $original = '{"OWNER":"KeyProjects","age1":null,"ht1":null}';

#Literal entry.

my $desired  = '{"OWNER":"KeyProjects","scheduled":{"age1":null,"ht1":null}}';

#Literal entry.

my $data = decode_json($original); print Dumper $original; print Dumper $desired; print Dumper $data; for my $key ( keys % {$data} )

#Converts $data into a hash and cycles through it.

{ print "Found a key: $key", $/; if ( $key =~ /\A (?: age\d+ | ht\d+ ) \z/x ) { print " -> It matches our regular expression\n"; print " -> Deleting it from data structure\n"; my $value = delete $data->{$key};

#Does this delete the pair, the value, or what? See below.

print Dumper $key;

#Looks like nothing is deleted.

print Dumper $value;

#Looks like nothing is deleted.

print " -> Putting it back under sub-structure with key 'sche +duled'\n"; $data->{scheduled}{$key} = $value;

#I should understand this step but I don't really know what each aspect of this line is doing.

print Dumper $key; print Dumper $value; print Dumper $data; } else { print " -> It's fine where it is, no action taken\n"; print Dumper $key; print Dumper $data; } } print encode_json( $data ), $/; use Test::More; my $desired_data = decode_json( $desired ); is_deeply( $desired_data, $data, "Data structures match" ); done_testing(1);

In reply to Re^4: Find a Position and Insert Text by jlb333333
in thread Find a Position and Insert Text by jlb333333

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.