in reply to Re^8: Perl Database Entries
in thread Perl Database Entries
What is the difference between my $unjson=$json->allow_nonref->decode($api_results); and
What happened differently when you replaced the $ with @? what was the contents of @unjson in your versionmy @unjson=$json->allow_nonref->decode($api_results);
What is the difference between
andfor my $row (@unjson) {
What happened differently between the two after the change to @unjson=for my $row (@$unjson) {
What is the difference between
andfor my $var (qw/.id .slug .name .provider.id .provider.name .../){
What happened differently after you made that changefor my $var (qw/.id, .slug, .name, .provider.id, .provider.name,.../) +{
Yes the substr removed the leading dot, but its presence was more to remove a leading blank token after the split. The purpose of the split had less to do with removing the dots but instead broke the value into its subparts that were separated by the periods. $row is a hash reference, we did not transfer any json data in that assignment but instead made a copy of the pointer into a working variable that we could then modify without consequence. The scalar value of an array is the number of members in that array. The loop will only first execute if there was more than one period separated subpart to the name/value and will continue to execute while there are still subparts to deal with. $subpart represents the next value in the chain of array references we want to deal with. $base=$base->{$subpart}; then places into $base the reference to the subarray we named via $subpart. if $var was a.b.c on the first loop of the while $base now points to the hash $row->{a} instead of $row. on the second pass of the while loop $base will become $base->{b} which would be the same as $row->{a}{b}. As pop removed subparts from the array the loop finishes when there are no more subparts left in the array and $base is left as the pointer to the deepest hash we need so that $base->{$terminal} will point to the value of the last name of the original @parts. IF there was only 1 subart in the original @parts $base still points to the original hash of $row. if there were 2 subparts left after terminal was popped off, such as in a.b.c $base now points to $row->{a}{b} and $row->{a}{b}{c} would be placed into @insert. If there was only a terminal in $var (such as d) $row->{d} would be placed into @insert since $base would have never been changed from its original setting of $row.
What was the difference between what you posted as $api_results in Re^4: Perl Database Entries and Re^6: Perl Database Entries. What was still wrong with the supposed json in Re^6: Perl Database Entries, (hint there were two errors that poj fixed for you without mentioning them)
So you skipped explaining what went wrong when you changed what i posted, you still dont understand how not telling us what your data was or why posting incorrect data presented a problem in determining what needed to be done, and you dont understand what happened when you changed the for $var (qw/.../) sequence. Given the explanation above ill let you grade yourself on your understanding of what the perl simulation of jg did
.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Perl Database Entries
by huck (Prior) on Jul 17, 2017 at 02:04 UTC |