Code-
$col1->insert("_id" => '100',
"results" => {
"result" => "1",
"when" => "sunday"
}
);
the error is-
Can't use string ("100") as a HASH ref while "strict refs" in use at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/MongoDB/Collection.pm line xyz.
What is wrong here?
The
insertmethod in MongoDB::Collection wants a hash-ref, not a list. You want to say this:Note the
({and}). Theinsertmethod actually takes hash-ref arguments. So insideinsert, it will do something like this:But your original call will put
'_id'in$objand'100'in$optsand that’s where your error message comes from. Keep in mind that=>is just another way of saying,so yourinsertcall was really: