It took me a while to figure out why I was writing junk to the DB. More or less, this is my code.
my $request = get_request( $request_id ) ; my $to_wiki = $request ;
I thought to be making a copy of the hash in the hashref.
I meant to be making a copy of the hash in the hashref.
I wasn't making a copy of the hash in the hashref. I was making a copy of the hashref address. Which means every change I made to $to_wiki, I made to $request.
Instead, I needed to do something more like this.
my $request = get_request( $request_id ) ; my $to_wiki ; %$to_wiki = map { $_ => $request->{ $_ } } keys %$request ;
I present this as a cautionary tale. Please, learn from the mistakes of others.
No comments:
Post a Comment