Update your original post.
You can't delete it, but you can modify it and add stuff to it.
Everybody here occasionally makes mistakes.
Not a big deal.
| [reply] |
Marshall hits the nail on the head here. While you cannot delete your original node, you can edit it.
If you originally asked a question for which you have found the answer, just add the answer into the question with an edit. This will enable others to find the question (and answer!) should they be searching for answers to the same (or a similar) question.
| [reply] |
I just realized the question is useless.
I'm not sure why you think so, how to take a slice of a hash is a valid question, maybe you could explain what resolution you found for your question?
Anyway, there are several ways to make a (shallow) copy of a part of a hash, here are a few:
- Using map: %slice = map { $_ => $hash{$_} } @keys;
- Using Foreach Loops (in this case as a statement modifier): $slice{$_} = $hash{$_} for @keys;
- Using Slices: @slice{@keys} = @hash{@keys};
- Using Key/Value Hash Slices, new in Perl 5.20: %slice = %hash{@keys};
my %h is really big and I don't have enough RAM to make a copy of it
This makes the question interesting. It turns out that, at least on my machine with Perl 5.26, from the options above:
- map takes the most memory, about 180% as much as a regular @ slice,
- a regular @ slice takes about as much memory as a key/value % slice,
- a key/value % slice takes about as much memory as a regular @ slice, and
- the for loop variant takes the least amount of memory, taking only about 88% of a regular @ slice.
I want to load the slice directly into a hashref
As it turns out, changing my %slice into my $slice and changing the syntaxes into the following doesn't really make a big difference:
- $slice = { map { $_ => $hash{$_} } @keys }; - about 6% more memory
- @{$slice}{@keys} = @hash{@keys}; - about the same amount of memory
- $slice = {%hash{@keys}}; - about the same amount of memory
- $slice->{$_} = $hash{$_} for @keys; - about the same amount of memory
On the other hand, if for example the values in your hash are huge, then perhaps a different approach is needed - for example, in your second hash you could store references to the values of the first hash. Or, you may not even need to create a second hash in the first place, perhaps simply keeping the list of keys around to select values from the first hash is enough.
| [reply] [d/l] [select] |
Just about every question whether it seems pointless or silly or whatever contributes to the site and often sparks interesting replies so is considered worth keeping. It's the ethos of the place that things are transparent so deletions or silent redaction are frowned upon, sometimes openly blocked. I don't have a dog in the no deleted nodes fight but don't mind going with the flow either.
| [reply] |
I asked a question, then realized that there was no point in asking what I was asking.
Don't worry, just about everyone here has had moments like that. How do I change/delete my post? explains a bit more about what the others have said, that it's best to either edit your original post (or answer your own question), so that others who may have the same question can learn from it.
| [reply] |
I'm so tempted to frontpage this. | [reply] |
Because not allowing users to delete nodes is frankly silly, not matter what tales are told about why it isn't allowed.
| [reply] |