Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: iterating through json decode

by Eily (Monsignor)
on Feb 08, 2018 at 14:38 UTC ( [id://1208716]=note: print w/replies, xml ) Need Help??


in reply to iterating through json decode

\@{$ref} is the same as $ref, because @{$ref} accesses the array that $ref points to, and adding a \ gets the same reference.

While accessing @_ inside a function does work, I think you should put your arguments in variable (which should be done when @_ isn't a list of similar things but each argument has its own meaning. So:

sub repl_mongo{ my ($ref, $depth) = @_; return unless $depth; if (ref($ref) eq 'ARRAY') { ... }
(and basically replace every use of $_[0] by $ref, and $_[1] by $depth).

foreach my $item (keys %{$_[0]}){ repl_mongo($key,$_[1]-1 ); } The loop variable is $item, but you access $key. Do you have strict on? It should have told you about that.

And for the date conversion, after you have found that a string starts with ISODate (that's index exactly 0 by the way) you can use substr to extract the date part (which will always be at the same positions, starting from the 8th character).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1208716]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found